Skip to content

Commit 3646a64

Browse files
committed
Fix HttpBindingsMissing skipping REST protocol services
The `HttpBindingsMissingValidator` had a top-level short-circuit that returned early when no shape in the model carried `@http`. Services with a protocol like `restJson1` that requires `@http` on all operations would pass validation silently when no operations had the trait yet.
1 parent 607bea7 commit 3646a64

6 files changed

Lines changed: 98 additions & 120 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "bugfix",
3+
"description": "Fixed a bug where HttpBindingMissing validation didn't fire if a service requiring `@http` traits had none at all.",
4+
"pull_requests": [
5+
"[#3122](https://github.com/smithy-lang/smithy/pull/3122)"
6+
]
7+
}

smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/HttpBindingsMissingValidator.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
package software.amazon.smithy.model.validation.validators;
66

7-
import java.util.Collections;
87
import java.util.List;
98
import java.util.Set;
109
import java.util.stream.Collectors;
@@ -29,10 +28,6 @@
2928
public final class HttpBindingsMissingValidator extends AbstractValidator {
3029
@Override
3130
public List<ValidationEvent> validate(Model model) {
32-
if (!model.isTraitApplied(HttpTrait.class)) {
33-
return Collections.emptyList();
34-
}
35-
3631
TopDownIndex topDownIndex = TopDownIndex.of(model);
3732
return model.shapes(ServiceShape.class)
3833
.flatMap(shape -> validateService(topDownIndex, model, shape).stream())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[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
2+
[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 numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
$version: "2.0"
2+
3+
namespace ns.foo
4+
5+
@trait(selector: "service")
6+
@protocolDefinition(traits: [
7+
smithy.api#cors
8+
smithy.api#endpoint
9+
smithy.api#hostLabel
10+
smithy.api#http
11+
smithy.api#httpError
12+
smithy.api#httpHeader
13+
smithy.api#httpLabel
14+
smithy.api#httpPayload
15+
smithy.api#httpPrefixHeaders
16+
smithy.api#httpQuery
17+
smithy.api#httpQueryParams
18+
smithy.api#httpResponseCode
19+
smithy.api#jsonName
20+
smithy.api#timestampFormat
21+
])
22+
@documentation("A simple clone of AWS restJson1.")
23+
structure restProtocol {}
24+
25+
@restProtocol
26+
service MyService {
27+
version: "2017-01-17"
28+
operations: [MissingBindings1, MissingBindings2]
29+
}
30+
31+
@readonly
32+
operation MissingBindings1 {
33+
input := {}
34+
output := {}
35+
}
36+
37+
@readonly
38+
operation MissingBindings2 {
39+
input := {}
40+
output := {}
41+
}

smithy-model/src/test/resources/software/amazon/smithy/model/errorfiles/validators/http-bindings-missing-validator.json

Lines changed: 0 additions & 115 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
$version: "2.0"
2+
3+
namespace ns.foo
4+
5+
@trait(selector: "service")
6+
@protocolDefinition(traits: [
7+
smithy.api#cors
8+
smithy.api#endpoint
9+
smithy.api#hostLabel
10+
smithy.api#http
11+
smithy.api#httpError
12+
smithy.api#httpHeader
13+
smithy.api#httpLabel
14+
smithy.api#httpPayload
15+
smithy.api#httpPrefixHeaders
16+
smithy.api#httpQuery
17+
smithy.api#httpQueryParams
18+
smithy.api#httpResponseCode
19+
smithy.api#jsonName
20+
smithy.api#timestampFormat
21+
])
22+
@documentation("A simple clone of AWS restJson1.")
23+
structure restProtocol {}
24+
25+
@restProtocol
26+
service MyService {
27+
version: "2017-01-17"
28+
operations: [HasBindings, MissingBindings1, MissingBindings2]
29+
}
30+
31+
@readonly
32+
@http(method: "GET", uri: "/A")
33+
operation HasBindings {
34+
input := {}
35+
output := {}
36+
}
37+
38+
@readonly
39+
operation MissingBindings1 {
40+
input := {}
41+
output := {}
42+
}
43+
44+
@readonly
45+
operation MissingBindings2 {
46+
input := {}
47+
output := {}
48+
}

0 commit comments

Comments
 (0)