Bug Report Checklist
Issue title: [BUG][typescript-nestjs-server] Header parameters generated without @Headers() decorator; values never bound at runtime
Description
The typescript-nestjs-server generator does not emit NestJS @Headers() decorators for OpenAPI parameters with in: header. The generated controller has plain method parameters (e.g. xRequestId: string, xIdempotencyKey: string) with no decorator. In NestJS, only parameters with a decorator (@Body(), @Param(), @Query(), @Headers(), etc.) are bound from the request. As a result, header parameter values are always undefined at runtime even when the client sends the headers.
The generator's documentation lists "Header" as a supported parameter feature (OAS2/OAS3), but the generated code does not fulfill this for NestJS.
openapi-generator version
- Version used: 7.17.0 (via
@openapitools/openapi-generator-cli 2.28.x)
- Regression: Unknown; not tested on earlier versions.
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Example API
version: 1.0.0
paths:
/items:
post:
operationId: createItem
parameters:
- name: x-request-id
in: header
required: false
schema:
type: string
- name: x-idempotency-key
in: header
required: false
schema:
type: string
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
'201':
description: Created
Generation Details
CLI command:
npx @openapitools/openapi-generator-cli generate \
-i openapi.yaml \
-g typescript-nestjs-server \
-o ./out \
--additional-properties=useSingleRequestParameter=true,importFileExtension=.js,supportsES6=true
- Generator: typescript-nestjs-server
- Options: useSingleRequestParameter=true (and commonly used .js/supportsES6 for Node)
Steps to reproduce
- Save the YAML above as
openapi.yaml.
- Run the generation command above.
- Open
out/controllers/Default.controller.ts (or the generated controller for the operation).
- Observe that the
createItem method has parameters xRequestId: string and xIdempotencyKey: string with no @Headers('...') decorator.
What's the actual output vs expected output?
Actual (excerpt): Header parameters are plain arguments; Nest does not bind them.
createItem(
@Body() body: object,
xRequestId: string,
xIdempotencyKey: string,
@Req() request: Request
): SomeResponse | Promise<SomeResponse> | Observable<SomeResponse> {
return this.api.createItem({ body, xRequestId, xIdempotencyKey }, request);
}
Expected (excerpt): Header parameters should have @Headers() so Nest binds values from the request.
createItem(
@Body() body: object,
@Headers('x-request-id') xRequestId: string,
@Headers('x-idempotency-key') xIdempotencyKey: string,
@Req() request: Request
): SomeResponse | Promise<SomeResponse> | Observable<SomeResponse> {
return this.api.createItem({ body, xRequestId, xIdempotencyKey }, request);
}
The controller should also import Headers from @nestjs/common.
Related issues/PRs
Suggest a fix
The generator's NestJS controller template (likely under modules/openapi-generator/src/main/resources/typescript-nestjs-server/) should emit @Headers('{{paramName}}') (or the appropriate mustache variable for the header name) for parameters where param.isHeader or equivalent is true, and include Headers in the @nestjs/common import. This would align the generated code with Nest's parameter binding and the documented Header parameter support.
Bug Report Checklist
Issue title:
[BUG][typescript-nestjs-server] Header parameters generated without @Headers() decorator; values never bound at runtimeDescription
The typescript-nestjs-server generator does not emit NestJS
@Headers()decorators for OpenAPI parameters within: header. The generated controller has plain method parameters (e.g.xRequestId: string,xIdempotencyKey: string) with no decorator. In NestJS, only parameters with a decorator (@Body(),@Param(),@Query(),@Headers(), etc.) are bound from the request. As a result, header parameter values are alwaysundefinedat runtime even when the client sends the headers.The generator's documentation lists "Header" as a supported parameter feature (OAS2/OAS3), but the generated code does not fulfill this for NestJS.
openapi-generator version
@openapitools/openapi-generator-cli2.28.x)OpenAPI declaration file content or url
Generation Details
CLI command:
Steps to reproduce
openapi.yaml.out/controllers/Default.controller.ts(or the generated controller for the operation).createItemmethod has parametersxRequestId: stringandxIdempotencyKey: stringwith no@Headers('...')decorator.What's the actual output vs expected output?
Actual (excerpt): Header parameters are plain arguments; Nest does not bind them.
Expected (excerpt): Header parameters should have
@Headers()so Nest binds values from the request.The controller should also import
Headersfrom@nestjs/common.Related issues/PRs
Suggest a fix
The generator's NestJS controller template (likely under
modules/openapi-generator/src/main/resources/typescript-nestjs-server/) should emit@Headers('{{paramName}}')(or the appropriate mustache variable for the header name) for parameters whereparam.isHeaderor equivalent is true, and includeHeadersin the@nestjs/commonimport. This would align the generated code with Nest's parameter binding and the documented Header parameter support.