swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.04k stars 6.03k forks source link

[Java Spring] Response headers not generated from swagger file #9079

Open carelessWhisper2 opened 5 years ago

carelessWhisper2 commented 5 years ago
Description

When generating a new API interface, the response headers declared in the swagger file is not included in the @ApiResponse annotation, they are simply ignored

Swagger-codegen version

2.4.0

Swagger declaration file content or url
    "201DomesticPaymentConsentsCreated": {
      "description": "Domestic Payment Consents Created",
      "headers": {
        "x-fapi-interaction-id": {
          "type": "string",
          "description": "An RFC4122 UID used as a correlation id."
        },
        "x-jws-signature": {
          "type": "string",
          "description": "Header containing a detached JWS signature of the body of the payload."
        }
      },
      "schema": {
        "$ref": "#/definitions/OBWriteDomesticConsentResponse1"
      }
    }

Generated annotation missing the headers

    @ApiResponse(
            code = 201,
            message = "Domestic Payment Consents Created",
            response = OBWriteDomesticConsentResponse1.class
    )
Command line used for generation

java -jar swagger-codegen-cli.jar generate -i swagger.json -l spring --additional-properties interfaceOnly=true,dateLibrary=java8,serializableModel=true,java8=true

Steps to reproduce
  1. Retrieve swagger file from openbanking uk repo https://github.com/OpenBankingUK/read-write-api-specs/blob/v3.0.0/dist/payment-initiation-swagger.json

  2. Generate using command line above

Related issues/PRs
Suggest a fix/enhancement

How the @ApiResponse annotation should look like

    @ApiResponse(
            code = 201,
            message = "Domestic Payment Consents Created",
            response = OBWriteDomesticConsentResponse1.class,
            responseHeaders = {
                    @ResponseHeader(name = "x-fapi-interaction-id", response = String.class, description = "An RFC4122 UID used as a correlation id."),
                    @ResponseHeader(name = "x-jws-signature", response = String.class, description = "Header containing a detached JWS signature of the body of the payload.")
            }
    )
morepe commented 8 months ago

Is there any update on this old bug? Just ran into the same issue in version 7.2.0