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

fix enum schema #2970

Merged
merged 1 commit into from
Oct 24, 2024
Merged

fix enum schema #2970

merged 1 commit into from
Oct 24, 2024

Conversation

eugleenyc
Copy link

@eugleenyc eugleenyc commented Jun 4, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

As outlined in the issue 2761: The schema is being overwritten in apiHeader if an enum is provided.

A demo repo with instructions can be found at https://github.com/eugleenyc/swagger-fix-demo/

How to see the defect:

The resulting yaml will show the following:

openapi: 3.0.0
paths:
  /:
    get:
      operationId: AppController_getHello
      parameters:
        - name: testHeader
          required: true
          in: header
          description: test description
          schema:
            enum:
              - an enum
            type: string
      responses:
        '200':
          description: ''
info:
  title: demo project
  description: demo project description
  version: '1.0'
  contact: {}
tags:
  - name: demo
    description: ''
servers: []
components:
  schemas: {}

This is not correct as in the controller it specifies a default value.

Issue Number: 2761

What is the new behavior?

As outline in the repo here for the potential swagger fix.
If you include a spread operator in the code outlined here

Screenshot 2024-06-05 at 8 31 43 AM

It will now return the resulting correct yaml file:

openapi: 3.0.0
paths:
  /:
    get:
      operationId: AppController_getHello
      parameters:
        - name: testHeader
          required: true
          in: header
          description: test description
          schema:
            type: string
            default: default param
            enum:
              - an enum
      responses:
        '200':
          description: ''
info:
  title: demo project
  description: demo project description
  version: '1.0'
  contact: {}
tags:
  - name: demo
    description: ''
servers: []
components:
  schemas: {}

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@kamilmysliwiec
Copy link
Member

Not sure but this may lead to unsupported attributes in the schema

@kamilmysliwiec
Copy link
Member

Pardon, I didn't realize that you only updated the @ApiHeader decorator. LGTM then

@kamilmysliwiec kamilmysliwiec merged commit 36617c3 into nestjs:master Oct 24, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants