Issue
By default, the API method name is displayed as a summary in Swagger2
But, is not displayed in OpenApi3 by default.
How can I configure this property? Without using @Operation(summary = "Summary")
in each controller endpoint.
Dependency: implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.5.10'
Solution
The method name in OpenAPI v3 is represented by the operationId
field.
Springdoc by default doesn't show the operationId
. To enable it, you'll need to set the below property to true
in your application's property file (for instance, application.properties
, application.yml
etc.)
springdoc.swagger-ui.displayOperationId=true
Although the operationId
can be specified explicitly like so
@Operation(summary = "Some method", operationId = "Operation 1", description = "Some Description")
which gives you the output as below
But if you don't specify the operationId
field explicitly, it defaults to the method name (which is your desired output).
Consider the below code sample
@PostMapping(value = "/create/{userId}", consumes = {MULTIPART_FORM_DATA_VALUE, IMAGE_PNG_VALUE, IMAGE_JPEG_VALUE, MULTIPART_MIXED_VALUE}, produces = {TEXT_PLAIN_VALUE})
@Operation(summary = "Save File", description = "Save the file to the disk")
public ResponseEntity<Object> saveFile(
@Parameter(description = "ID of the user")
@PathVariable(value = "userId") final String userId,
) {
return null;
}
@GetMapping(value = "/get", produces = MediaType.IMAGE_PNG_VALUE)
@ApiResponse(responseCode = "200", description = "OK", content = {@Content(schema = @Schema(type = "string", format = "binary"))})
public ResponseEntity<byte[]> getFile() {
return null;
}
The above code fragment will give the below output
Answered By - Debargha Roy
Answer Checked By - Senaida (JavaFixing Volunteer)