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

@Header.schema() in @ApiResponse does not generate the type #4668

Closed
emcintyre-hpe opened this issue May 8, 2024 · 1 comment
Closed

@Header.schema() in @ApiResponse does not generate the type #4668

emcintyre-hpe opened this issue May 8, 2024 · 1 comment
Assignees

Comments

@emcintyre-hpe
Copy link

Hello,

We're using Swagger annotations and Maven plugin to generate our spec. I'm attempting to add some @ApiResponse annotations to our operations, but the @Header annotation is not including the schema.type. For instance:

  @Operation(summary = "List of services for the given account",
             responses = {
                 @ApiResponse(responseCode = "200", description = "List of services for the given account"),
                 @ApiResponse(description = "User did not provide a valid auth token", responseCode = "401",
                              content = @Content(mediaType = MediaType.APPLICATION_JSON,
                                                 schema = @Schema(implementation = ErrorMessage.class)),
                              headers = { @Header(name = "testing-headers",
                                                  description = "Flow/trace ID for traceability in the logs",
                                                  schema = @Schema(type = "string")) })
             })

This generates the following spec:

    get:
      operationId: getServices
      parameters:
      - in: path
        name: accountId
        required: true
        schema:
          type:
          - string
      responses:
        "200":
          description: List of services for the given account
        "401":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorMessage'
          description: User did not provide a valid auth token
          headers:
            testing-headers:
              description: Flow/trace ID for traceability in the logs
              schema: {} # <- no `type: string` nested here 
              style: simple # <- not sure where this is coming from
      summary: List of services for the given account

Even if I add something like format to the @Schema:

    headers = { @Header(name = "testing-headers",
                        description = "Flow/trace ID for traceability in the logs",
                        schema = @Schema(type = "string", format = "hexadecimal")) })
            testing-headers:
              description: Flow/trace ID for traceability in the logs
              schema:
                format: hexadecimal
                # still no type
              style: simple

(Note that the motivation for adding the schema/type to the header is that linting tools complain about content/schema being required)

@micryc
Copy link
Contributor

micryc commented May 22, 2024

Hi @emcintyre-hpe could you share more details about your problem (e.g sample project), I tried to reproduce this bug, used exactly same annotations that you provided and schema type appears. Closing this ticket, feel free to reopen if issue still appears for you.

      parameters:
      - name: accountId
        in: path
        required: true
        schema:
          type: string
      responses:
        "200":
          description: List of services for the given account
        "401":
          description: User did not provide a valid auth token
          headers:
            testing-headers:
              description: Flow/trace ID for traceability in the logs
              style: simple
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorMessage'

@micryc micryc self-assigned this May 22, 2024
@micryc micryc closed this as completed May 23, 2024
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