Skip to content

Ordering of @ApiResponse entries in the resulting spec #2888

Closed
@philipp-paland

Description

@philipp-paland

Describe the bug

Multiple @ApiResponse annotations inside an @ApiResponses annotation do not keep their order when the openapi spec / "responses" field is generated.

To Reproduce
Steps to reproduce the behavior:

  @ApiResponses(
      value = {
        @ApiResponse(
            responseCode = "200",
            description = "OK."),
        @ApiResponse(
            responseCode = "401",
            description = "Unauthorized access.")
      })

leads to

"responses": {
          "401": {
            "description": "Unauthorized access."
          },
          "200": {
            "description": "OK."
            }
          }

Expected behavior

"responses": {
          "200": {
            "description": "OK."
            },
          "401": {
            "description": "Unauthorized access."
          }
          }

Additional context
I'm pretty sure the reason is that at https://github.com/springdoc/springdoc-openapi/blob/main/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/GenericResponseService.java#L486 the streams are collected with .collect(Collectors.toSet()) - collecting into a LinkedHashSet instead should lead to a stable ordering.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions