nestjs / swagger

OpenAPI (Swagger) module for Nest framework (node.js) :earth_americas:
https://nestjs.com
MIT License
1.68k stars 465 forks source link

Swagger decorator @ApiHeader is not including header on request #2906

Open douglasjunior opened 5 months ago

douglasjunior commented 5 months ago

Is there an existing issue for this?

Current behavior

Swagger decorator @ApiHeader is not including header on request

Code

@Controller('template')
export class TemplateController {

  @Get('test')
  @ApiHeader({
    name: 'accept',
  })
  async test(@Headers('accept') acceptHeader: string) {

    return `ok: ${acceptHeader}`;
  }

}

Result

image

Minimum reproduction code

https://codesandbox.io/p/devbox/green-cache-5xjgvc

Steps to reproduce

Just create a new NestJS project and add a new Controller like TemplateController above.

Expected behavior

Expect that Swagger UI to include the proper accept value on request.

Package

Other package

@nestjs/swagger

NestJS version

10.3.3

Packages versions

    "@nestjs/common": "10.3.3",
    "@nestjs/config": "3.2.0",
    "@nestjs/core": "10.3.3",
    "@nestjs/platform-express": "10.3.3",
    "@nestjs/swagger": "7.3.0",
    "class-transformer": "0.5.1",
    "class-validator": "0.14.1",

Node.js version

18.12.0

In which operating systems have you tested?

Other

No response

letsaguiar commented 5 months ago

this problem is specifically related to the 'accept' header. It works fine with other headers, but it doesn't with the accept header

Screenshot from 2024-04-15 11-16-52

Screenshot from 2024-04-15 11-17-20

douglasjunior commented 5 months ago

Confirmed in the provided example: https://codesandbox.io/p/devbox/green-cache-5xjgvc

image