openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

Generated code doen't have any information about response headers

Open gredwhite opened this issue 2 years ago • 2 comments

I have following open api specification description:

openapi: 3.0.3
...
  /foo:
    get:
      operationId: foo
      parameters:
        - name: bar
          in: query
          required: true
          schema:
            type: string
      responses:
        200:
          description: description
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string
          headers:
            myheader1:
              description: myheader1 desc
              schema:
                type: string
            myheader2:
              description: myheader2 desc
              schema:
                type: integer
        401:
          description: "Unauthorized"
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

The generated code is:

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2024-01-24T14:16:01.056664+03:00[Europe/London]")
@Validated
@Tag(name = "Default", description = "the Default API")
@RequestMapping("${openapi.directoryServiceManager.base-path:/api/v1}")
public interface DefaultApi {

    /**
     * GET /foo
     *
     * @param bar  (required)
     * @return description (status code 200)
     *         or Unauthorized (status code 401)
     */
    @Operation(
        operationId = "foo",
        responses = {
            @ApiResponse(responseCode = "200", description = "description", content = {
                @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = String.class)))
            }),
            @ApiResponse(responseCode = "401", description = "Unauthorized", content = {
                @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDto.class))
            })
        }
    )
    @RequestMapping(
        method = RequestMethod.GET,
        value = "/foo",
        produces = { "application/json" }
    )
    ResponseEntity<List<String>> foo(
        @NotNull 
@Parameter(name = "bar", description = "", required = true, in = ParameterIn.QUERY) @Valid @RequestParam(value = "bar", required = true) String bar
    );

}

As you can see where is no information about response headers(myheader1 and myheader2)

I would expect that

ApiResponse should have headers argument added

Is there way to fix it ?

More information about environment:

buildscript {
    dependencies {
        classpath("org.openapitools:openapi-generator-gradle-plugin:5.0.0")
    }
}

plugins {
    java
    kotlin("jvm")
    kotlin("plugin.spring") version "1.8.21"  
    id("org.springframework.boot") version "3.1.4"
    id("org.openapi.generator") version "6.3.0"
}

gredwhite avatar Jan 24 '24 09:01 gredwhite

Also running into this

MikeLamsma avatar Jun 20 '24 12:06 MikeLamsma

Any update here?

JohannesProbst avatar Oct 14 '24 10:10 JohannesProbst