Skip to content

[BUG] [Java] [spring-boot] Code generated from a specification with a default response indicates the wrong return code #14394

@GregDThomas

Description

@GregDThomas

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The specification allows a "default" response to be used, typically for error payloads - https://swagger.io/specification/#path-item-object-example

If code is generated using a "default" response then the wrong HTTP return code is indicated;

    @Operation(
        operationId = "getPetsById",
        summary = "Find pets by ID",
        responses = {
            @ApiResponse(responseCode = "200", description = "pet response", content = {
                @Content(mediaType = "application/xml", array = @ArraySchema(schema = @Schema(implementation = Pet.class))),
                @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = Pet.class)))
            }),
            @ApiResponse(responseCode = "200", description = "error payload"
            )
        }
    )

Note the responseCode for the "error payload" is 200. It should be "default".

This means anyone examining the generated code will get a misleading idea of what the response could be.

openapi-generator version

6.2.1

OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions