Open alexgordtop opened 1 year ago
Another example, where the default response leads to a ambiguous generation result:
-> responseCode 200 is contained with two different schemas...
@Operation(summary = "Returns all Asset Administration Shell Descriptors", description = "", tags={ "Asset Administration Shell Registry API" })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Requested Asset Administration Shell Descriptors", content = @Content(mediaType = "application/json", schema = @Schema(implementation = GetAssetAdministrationShellDescriptorsResult.class))),
@ApiResponse(responseCode = "400", description = "Bad Request, e.g. the request parameters of the format of the request body is wrong.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Result.class))),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Result.class))),
@ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Result.class))),
@ApiResponse(responseCode = "200", description = "Default error handling for unmentioned status codes", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Result.class))) })
@RequestMapping(value = "/shell-descriptors",
produces = { "application/json" },
method = RequestMethod.GET)
ResponseEntity<GetAssetAdministrationShellDescriptorsResult> getAllAssetAdministrationShellDescriptors(....);
What?
The "default" return code, that is used in the swagger api to document the default error response, leads to wrong server stub generation in spring and other frameworks:
The default is usually interpreted as default successful response. For code generation, the default response defines the return type of the generated method - while the error codes are handled via custom exceptions.
How?
Remove the "default" response. When 400 is documented, 403 would usually be accepted with the same response type. There are ways to check for "client" oder "server" errors.
https://github.com/spring-projects/spring-framework/blob/main/spring-web/src/main/java/org/springframework/http/HttpStatus.java#L483