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

Fix logic for deciding when to write a default input body and content-type #1304

Merged
merged 1 commit into from
Jun 17, 2024
Merged
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 @@ -1096,7 +1096,7 @@ private void writeContentTypeHeader(GenerationContext context, Shape operationOr
optionalContentType = bindingIndex.determineResponseContentType(operationOrError, getDocumentContentType());
}
// If we need to write a default body then it needs a content type.
if (!optionalContentType.isPresent() && shouldWriteDefaultBody(context, operationOrError, isInput)) {
if (optionalContentType.isEmpty() && shouldWriteDefaultBody(context, operationOrError, isInput)) {
optionalContentType = Optional.of(getDocumentContentType());
}
optionalContentType.ifPresent(contentType -> {
Expand Down Expand Up @@ -1143,16 +1143,16 @@ private boolean shouldWriteDefaultBody(GenerationContext context, Shape operatio
}

/**
* Given a context and operation, should a default input body be written. By default no body will be written
* if there are no members bound to the input.
* Given a context and operation, should a default input body be written. By default, a body
* will be written if and only if there are payload members bound to the input.
*
* @param context The generation context.
* @param operation The operation whose input is being serialized.
*
* @return True if a default body should be generated.
*/
protected boolean shouldWriteDefaultInputBody(GenerationContext context, OperationShape operation) {
return HttpBindingIndex.of(context.getModel()).getRequestBindings(operation).isEmpty();
return HttpBindingIndex.of(context.getModel()).hasRequestBody(operation);
}

/**
Expand Down
Loading