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

Clarify http payload binding error message #959

Merged
merged 1 commit into from
Oct 27, 2021
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
Expand Up @@ -116,16 +116,29 @@ private List<ValidationEvent> validateOperation(

List<HttpBinding> payloadBindings = bindingIndex.getRequestBindings(shape, HttpBinding.Location.PAYLOAD);
List<HttpBinding> documentBindings = bindingIndex.getRequestBindings(shape, HttpBinding.Location.DOCUMENT);
if (semantics.allowsRequestPayload != null
&& !semantics.allowsRequestPayload
&& (!payloadBindings.isEmpty() || !documentBindings.isEmpty())) {
// Detect location and combine to one list for messages
String document = payloadBindings.isEmpty() ? "document" : "payload";
payloadBindings.addAll(documentBindings);
events.add(danger(shape, trait, String.format(
"This operation uses the `%s` method in the `http` trait, but "
+ "has the following members bound to the %s: %s", method, document,
ValidationUtils.tickedList(payloadBindings.stream().map(HttpBinding::getMemberName)))));
if (semantics.allowsRequestPayload != null && !semantics.allowsRequestPayload) {
if (!payloadBindings.isEmpty()) {
events.add(danger(shape, trait, String.format(
"This operation uses the `%s` method in the `http` trait, but the `%s` member is sent as the "
+ "payload of the request because it is marked with the `httpPayload` trait. Many HTTP "
+ "clients do not support payloads with %1$s requests. Consider binding this member to "
+ "other parts of the HTTP request such as a query string parameter using the `httpQuery` "
+ "trait, a header using the `httpHeader` trait, or a path segment using the `httpLabel` "
+ "trait.",
method, payloadBindings.get(0).getMemberName()
)));
} else if (!documentBindings.isEmpty()) {
events.add(danger(shape, trait, String.format(
"This operation uses the `%s` method in the `http` trait, but the following members "
+ "are sent as part of the payload of the request: %s. These members are sent as part "
+ "of the payload because they are not explicitly configured to be sent in headers, in the "
+ "query string, or in a URI segment. Many HTTP clients do not support payloads with %1$s "
+ "requests. Consider binding these members to other parts of the HTTP request such as "
+ "query string parameters using the `httpQuery` trait, headers using the `httpHeader` "
+ "trait, or URI segments using the `httpLabel` trait.",
method, ValidationUtils.tickedList(documentBindings.stream().map(HttpBinding::getMemberName))
)));
}
}

return events;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[DANGER] ns.foo#K: This operation uses the `GET` method in the `http` trait, but has the following members bound to the payload: `payload` | HttpMethodSemantics
[DANGER] ns.foo#L: This operation uses the `GET` method in the `http` trait, but has the following members bound to the document: `payload` | HttpMethodSemantics
[DANGER] ns.foo#M: This operation uses the `DELETE` method in the `http` trait, but has the following members bound to the document: `payload` | HttpMethodSemantics
[DANGER] ns.foo#K: This operation uses the `GET` method in the `http` trait, but the `payload` member is sent as the payload of the request because it is marked with the `httpPayload` trait. Many HTTP clients do not support payloads with GET requests. Consider binding this member to other parts of the HTTP request such as a query string parameter using the `httpQuery` trait, a header using the `httpHeader` trait, or a path segment using the `httpLabel` trait. | HttpMethodSemantics
[DANGER] ns.foo#L: This operation uses the `GET` method in the `http` trait, but the following members are sent as part of the payload of the request: `payload`. These members are sent as part of the payload because they are not explicitly configured to be sent in headers, in the query string, or in a URI segment. Many HTTP clients do not support payloads with GET requests. Consider binding these members to other parts of the HTTP request such as query string parameters using the `httpQuery` trait, headers using the `httpHeader` trait, or URI segments using the `httpLabel` trait. | HttpMethodSemantics
[DANGER] ns.foo#M: This operation uses the `DELETE` method in the `http` trait, but the following members are sent as part of the payload of the request: `payload`. These members are sent as part of the payload because they are not explicitly configured to be sent in headers, in the query string, or in a URI segment. Many HTTP clients do not support payloads with DELETE requests. Consider binding these members to other parts of the HTTP request such as query string parameters using the `httpQuery` trait, headers using the `httpHeader` trait, or URI segments using the `httpLabel` trait. | HttpMethodSemantics
[WARNING] ns.foo#G: This operation uses the `POST` method in the `http` trait, but is marked with the readonly trait | HttpMethodSemantics
[WARNING] ns.foo#H: This operation uses the `DELETE` method in the `http` trait, but is not marked with the idempotent trait | HttpMethodSemantics
[WARNING] ns.foo#I: This operation uses the `GET` method in the `http` trait, but is not marked with the readonly trait | HttpMethodSemantics
Expand Down