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

Ordering of @ApiResponse entries in the resulting spec #2888

Closed
philipp-paland opened this issue Feb 4, 2025 · 2 comments
Closed

Ordering of @ApiResponse entries in the resulting spec #2888

philipp-paland opened this issue Feb 4, 2025 · 2 comments

Comments

@philipp-paland
Copy link

philipp-paland commented Feb 4, 2025

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.

@philipp-paland
Copy link
Author

Thanks for taking care of this :)

@ranger-ross
Copy link

thank you for fixing this. I ran into this issue with parameters and generating clients.
I'll be upgrading to 2.8.5 soon :)

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