Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "bugfix",
"description": "Fixed a bug where HttpBindingMissing validation didn't fire if a service requiring `@http` traits had none at all.",
"pull_requests": [
"[#3122](https://github.com/smithy-lang/smithy/pull/3122)"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ service MyService {
}
}

@http(method: "POST", uri: "/say-hello")
operation SayHello {
input: SayHelloInput,
output: SayHelloOutput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
package software.amazon.smithy.model.validation.validators;

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -29,10 +28,6 @@
public final class HttpBindingsMissingValidator extends AbstractValidator {
@Override
public List<ValidationEvent> validate(Model model) {
if (!model.isTraitApplied(HttpTrait.class)) {
return Collections.emptyList();
}

TopDownIndex topDownIndex = TopDownIndex.of(model);
return model.shapes(ServiceShape.class)
.flatMap(shape -> validateService(topDownIndex, model, shape).stream())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[ERROR] ns.foo#MissingBindings1: The `ns.foo#restProtocol` protocol requires all operations in the `ns.foo#MyService` service define the `http` trait, but this operation is missing the `http` trait. | HttpBindingsMissing
[ERROR] ns.foo#MissingBindings2: The `ns.foo#restProtocol` protocol requires all operations in the `ns.foo#MyService` service define the `http` trait, but this operation is missing the `http` trait. | HttpBindingsMissing
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
$version: "2.0"

namespace ns.foo

@trait(selector: "service")
@protocolDefinition(traits: [
smithy.api#cors
smithy.api#endpoint
smithy.api#hostLabel
smithy.api#http
smithy.api#httpError
smithy.api#httpHeader
smithy.api#httpLabel
smithy.api#httpPayload
smithy.api#httpPrefixHeaders
smithy.api#httpQuery
smithy.api#httpQueryParams
smithy.api#httpResponseCode
smithy.api#jsonName
smithy.api#timestampFormat
])
@documentation("A simple clone of AWS restJson1.")
structure restProtocol {}

@restProtocol
service MyService {
version: "2017-01-17"
operations: [MissingBindings1, MissingBindings2]
}

@readonly
operation MissingBindings1 {
input := {}
output := {}
}

@readonly
operation MissingBindings2 {
input := {}
output := {}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
$version: "2.0"

namespace ns.foo

@trait(selector: "service")
@protocolDefinition(traits: [
smithy.api#cors
smithy.api#endpoint
smithy.api#hostLabel
smithy.api#http
smithy.api#httpError
smithy.api#httpHeader
smithy.api#httpLabel
smithy.api#httpPayload
smithy.api#httpPrefixHeaders
smithy.api#httpQuery
smithy.api#httpQueryParams
smithy.api#httpResponseCode
smithy.api#jsonName
smithy.api#timestampFormat
])
@documentation("A simple clone of AWS restJson1.")
structure restProtocol {}

@restProtocol
service MyService {
version: "2017-01-17"
operations: [HasBindings, MissingBindings1, MissingBindings2]
}

@readonly
@http(method: "GET", uri: "/A")
operation HasBindings {
input := {}
output := {}
}

@readonly
operation MissingBindings1 {
input := {}
output := {}
}

@readonly
operation MissingBindings2 {
input := {}
output := {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import software.amazon.smithy.openapi.OpenApiException;
import software.amazon.smithy.openapi.OpenApiVersion;
import software.amazon.smithy.openapi.model.OpenApi;
import software.amazon.smithy.openapi.model.PathItem;
import software.amazon.smithy.utils.IoUtils;
import software.amazon.smithy.utils.ListUtils;
import software.amazon.smithy.utils.MapUtils;
Expand Down Expand Up @@ -271,31 +270,6 @@ public void omitsUnsupportedHttpMethods() {
Node.assertEquals(result, expectedNode);
}

@Test
public void protocolsCanOmitOperations() {
Model model = Model.assembler()
.addImport(getClass().getResource("missing-http-bindings.json"))
.discoverModels()
.assemble()
.unwrap();
OpenApiConfig config = new OpenApiConfig();
config.setService(ShapeId.from("smithy.example#Service"));
OpenApi result = OpenApiConverter.create()
.config(config)
.convert(model);

for (PathItem pathItem : result.getPaths().values()) {
assertFalse(pathItem.getGet().isPresent());
assertFalse(pathItem.getHead().isPresent());
assertFalse(pathItem.getDelete().isPresent());
assertFalse(pathItem.getPatch().isPresent());
assertFalse(pathItem.getPost().isPresent());
assertFalse(pathItem.getPut().isPresent());
assertFalse(pathItem.getTrace().isPresent());
assertFalse(pathItem.getOptions().isPresent());
}
}

@Test
public void addsEmptyResponseByDefault() {
Model model = Model.assembler()
Expand Down

This file was deleted.

Loading