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

API Versioning of type header is not supported #2235

Closed
2 of 4 tasks
DCampagnola opened this issue Jan 11, 2023 · 1 comment
Closed
2 of 4 tasks

API Versioning of type header is not supported #2235

DCampagnola opened this issue Jan 11, 2023 · 1 comment

Comments

@DCampagnola
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Enabling versioning with type "header", @nestjs/swagger doesn't generate the right documentation.

app.enableVersioning({
    type: VersioningType.HEADER,
    header: 'Accept-version',
  })

In the example I have two api in the same path with different versions

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  @Version('v1')
  getHello(@Query('old_example') example: string): string {
    return example;
  }

  @Get()
  @Version('v2')
  getHelloV2(@Query('example') example: string): string {
    return example;
  }
}

In the example above, I can call the v1 api with header 'Accept-Version': v1 and call the v2 api with header 'Accept-Version': v2.
This is the openapi generated:

{
  "openapi": "3.0.0",
  "paths": {
    "/": {
      "get": {
        "operationId": "AppController_getHelloV2",
        "parameters": [
          {
            "name": "example",
            "required": true,
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": ""
          }
        }
      }
    }
  },
  "info": {
    "title": "Cats example",
    "description": "The cats API description",
    "version": "1.0",
    "contact": {}
  },
  "tags": [
    {
      "name": "cats",
      "description": ""
    }
  ],
  "servers": [],
  "components": {
    "schemas": {}
  }
}

It has only the v2 version.
Screenshot 2023-01-11 alle 11 26 31
Also adding ApiImplicitHeader in each version doesn't resolve the issue

Minimum reproduction code

https://github.com/DCampagnola/nestjs-swagger-header-versioning-bug/tree/main

Steps to reproduce

  1. npm i
  2. npm start:dev
  3. Navigate in /api-json

Expected behavior

Generated api should include every version declared with the different docs

Package version

6.1.4

NestJS version

No response

Node.js version

No response

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@kamilmysliwiec
Copy link
Member

Let's track this here #2063

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants