Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate that query literal do not conflict with query params #1786

Merged
merged 2 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Address PR comments
  • Loading branch information
sugmanue committed May 31, 2023
commit a279fbdaa3e7e6020aabd8d948a6f10de2e75995
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,5 @@ public boolean equals(Object other) {
public int hashCode() {
return super.hashCode() + queryLiterals.hashCode();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
import java.util.Map;
import java.util.Set;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.knowledge.TopDownIndex;
import software.amazon.smithy.model.knowledge.OperationIndex;
import software.amazon.smithy.model.pattern.UriPattern;
import software.amazon.smithy.model.shapes.MemberShape;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.StructureShape;
import software.amazon.smithy.model.traits.HttpQueryTrait;
Expand Down Expand Up @@ -94,9 +93,8 @@ private List<ValidationEvent> validateBindings(
String literalKey = literalEntry.getKey();
if (entry.getValue().containsKey(literalKey)) {
events.add(error(entry.getKey(), String.format(
"`httpQuery` parameter name binding conflicts found for the `%s` parameter, the "
+ "http trait for the `%s` operation defines a query literal with the same name",
literalKey, operation.getId())));
"`httpQuery` name `%s` conflicts with the `http` trait of the `%s` operation: `%s`",
literalKey, operation.getId(), pattern)));
}
}
}
Expand All @@ -106,17 +104,13 @@ private List<ValidationEvent> validateBindings(
}

private Map<StructureShape, List<OperationShape>> getStructureToOperations(Model model) {
OperationIndex index = OperationIndex.of(model);
Map<StructureShape, List<OperationShape>> structureToOperations = new HashMap<>();
for (ServiceShape service : model.getServiceShapes()) {
for (OperationShape operation : TopDownIndex.of(model).getContainedOperations(service)) {
if (operation.hasTrait(HttpTrait.class)) {
model.expectShape(operation.getInputShape())
.asStructureShape()
.ifPresent(structure -> structureToOperations
.computeIfAbsent(structure, key -> new ArrayList<>())
.add(operation));
}
}
for (OperationShape operation : model.getOperationShapesWithTrait(HttpTrait.class)) {
index.getInput(operation)
.ifPresent(structure -> structureToOperations
.computeIfAbsent(structure, key -> new ArrayList<>())
.add(operation));
}
return structureToOperations;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[ERROR] smithy.example#OperationOneInput: `httpQuery` parameter name binding conflicts found for the `code` parameter, the http trait for the `smithy.example#OperationOne` operation defines a query literal with the same name | HttpQueryTrait
[ERROR] smithy.example#OperationOneInput: `httpQuery` name `code` conflicts with the `http` trait of the `smithy.example#OperationOne` operation: `/example?code` | HttpQueryTrait
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[ERROR] smithy.example#OperationOneInput: `httpQuery` parameter name binding conflicts found for the `code` parameter, the http trait for the `smithy.example#OperationOne` operation defines a query literal with the same name | HttpQueryTrait
[ERROR] smithy.example#OperationOneInput: `httpQuery` name `code` conflicts with the `http` trait of the `smithy.example#OperationOne` operation: `/example?code=bar` | HttpQueryTrait
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[ERROR] smithy.example#OperationOneInput: `httpQuery` parameter name binding conflicts found for the `code` parameter, the http trait for the `smithy.example#OperationOne` operation defines a query literal with the same name | HttpQueryTrait
[ERROR] smithy.example#OperationOneInput: `httpQuery` parameter name binding conflicts found for the `code` parameter, the http trait for the `smithy.example#OperationTwo` operation defines a query literal with the same name | HttpQueryTrait
[ERROR] smithy.example#OperationOneInput: `httpQuery` name `code` conflicts with the `http` trait of the `smithy.example#OperationOne` operation: `/one?code` | HttpQueryTrait
[ERROR] smithy.example#OperationOneInput: `httpQuery` name `code` conflicts with the `http` trait of the `smithy.example#OperationTwo` operation: `/two?code=bar` | HttpQueryTrait