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

JAX-RS endpoints without @ApiResponse annotation get a single "default" response code instead of "200" #4455

Closed
andrius-kurtinaitis opened this issue Jul 13, 2023 · 1 comment

Comments

@andrius-kurtinaitis
Copy link

andrius-kurtinaitis commented Jul 13, 2023

Example endpoint implementation:

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	@Operation(summary = "Retrieve an existing metro")
	public MetroDto get() {
		MetroVO vo = load();
		return MetroDto.from(vo);
	}

Generated openapi:

    "/metros/{id}" : {
      "get" : {
        "summary" : "Retrieve an existing metro",
        "operationId" : "get_3",
        "parameters" : [ {
          "name" : "id",
          "in" : "path",
          "required" : true,
          "schema" : {
            "type" : "integer",
            "format" : "int32"
          }
        } ],
        "responses" : {
          "default" : {
            "description" : "default response",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/MetroDto"
                }
              }
            }
          }
        }
      },

The openapi spec says:

The default MAY be used as a default response object for all HTTP codes that are not covered individually by the Responses Object.
The Responses Object MUST contain at least one response code, and if only one response code is provided it SHOULD be the response for a successful operation call.

https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#responsesObject

The Swagger OpenAPI guide (https://swagger.io/docs/specification/describing-responses/) says:

You can use the default response to describe these errors collectively, not individually. “Default” means this response is used for all HTTP codes that are not covered individually for this operation.

Consequently:

  • JAX-RS endpoint is responding with 200
  • spec requires at least one success code in Responses Object
  • "default" is a fallback not to be interpreted as "success" and allowed only in addition to other responses

=> "default" should not be used as a single response code in Responses Object.

@frantuma
Copy link
Member

#4482 introduces configuration property defaultResponseCode which allows to define the HTTP Status Code to use for such cases, replacing the default default.

Being this possibly opinionated and to maintain backward compatibility default is used when no config property is provided

Closing ticket, please reopen if still experiencing issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants