-
-
Notifications
You must be signed in to change notification settings - Fork 525
Is it possible to generate OpenApi doc with request body content for GET operation? #129
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
Comments
Hi, The behaviour that you are describing is normal with OpenAPI 3. Here is another reference, from the swagger official website about it: |
I was able to generate the OpenApi specification by defining the RequestBody for GET operation and hide the Parameter list at argument method level for the RequestBody. @GetMapping(value = "/get/client/info/", consumes = {MediaType.APPLICATION_JSON_VALUE}, produces =
{MediaType.APPLICATION_JSON_VALUE})
@Operation(summary = "Get client by client request body",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "ClientRequest body.",
content = @Content(schema = @Schema(implementation = ClientRequest.class)), required = true),
description = "Get the ClientAPI response object with uniqueue personal identification number as " +
"part of the request body.",
responses = {
@ApiResponse(responseCode = "200",
description = "The client", content = @Content(mediaType =
MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = ClientApi.class))),
@ApiResponse(responseCode = "400",
description = "Invalid personal identification number", content = @Content(mediaType =
MediaType.TEXT_PLAIN_VALUE,
schema = @Schema(example = "Invalid personal identification number."))),
@ApiResponse(responseCode = "404",
description = "Client not found.", content = @Content(mediaType =
MediaType.TEXT_PLAIN_VALUE,
schema = @Schema(example = "Client not found."))),
@ApiResponse(responseCode = "500", description = "Severe system failure has occured!", content =
@Content(mediaType = MediaType.TEXT_PLAIN_VALUE, schema = @Schema(
example = "Severe system failure has occured!")))})
public ResponseEntity<ClientApi> getClientInformationByRequestBody(@Parameter(hidden = true)
@ClientRequestBodyConstraint
@RequestBody ClientRequest clientRequest) {
ClientApi clientApi = openBankService.getClientInformationByPersonIdentification(clientRequest
.getPersonIdentificationNumber());
if (clientApi == null) {
throw new ClientNotFoundException("Client not found.");
}
return ResponseEntity.ok(clientApi);
} |
hi buddy, I kinda have the same situation, but my request body is an Object instead of ClientRequest clientRequest, happens that then Springdoc does not generate the request body in the API definition. Am I doing something wrong? |
Hi, my general problem is that my
@RequestBody
argument gets generated as parameters list instead (with POST/PUT it gets generated with request body content as supposed to), if I replace the parameters list with my request body content instead so I can execute the content with following curl command below, it works just fine.Is there something I am doing wrong? The
RFC 7231 specification states that
So it should be possible. If I am not doing anything wrong with my GET code operation below, will it be possible to generate request body content for GET RESTul operation in the future?
For my following @GetMapping operation I have the following:
The generated OpenApi GET operation content gets generated as:
The text was updated successfully, but these errors were encountered: