diff --git a/e2e/api-spec.json b/e2e/api-spec.json index d4ef615de..c33eec393 100644 --- a/e2e/api-spec.json +++ b/e2e/api-spec.json @@ -336,6 +336,7 @@ "required": false, "schema": { "type": "string", + "example": "test", "default": "test" } }, @@ -416,6 +417,7 @@ "required": false, "schema": { "type": "string", + "example": "test", "default": "test" } }, @@ -662,6 +664,7 @@ "required": false, "schema": { "type": "string", + "example": "test", "default": "test" } }, @@ -739,6 +742,7 @@ "required": false, "schema": { "type": "string", + "example": "test", "default": "test" } }, @@ -820,6 +824,7 @@ "required": false, "schema": { "type": "string", + "example": "test", "default": "test" } }, @@ -1039,6 +1044,7 @@ "required": false, "schema": { "type": "string", + "example": "test", "default": "test" } }, @@ -1113,6 +1119,7 @@ "required": false, "schema": { "type": "string", + "example": "test", "default": "test" } }, @@ -1183,6 +1190,7 @@ "required": false, "schema": { "type": "string", + "example": "test", "default": "test" } }, @@ -1269,6 +1277,7 @@ "required": false, "schema": { "type": "string", + "example": "test", "default": "test" } }, @@ -1326,6 +1335,7 @@ "required": false, "schema": { "type": "string", + "example": "test", "default": "test" } }, @@ -1396,6 +1406,7 @@ "required": false, "schema": { "type": "string", + "example": "test", "default": "test" } }, @@ -1463,6 +1474,7 @@ "required": false, "schema": { "type": "string", + "example": "test", "default": "test" } }, @@ -1542,6 +1554,7 @@ "required": false, "schema": { "type": "string", + "example": "test", "default": "test" } }, @@ -1601,6 +1614,7 @@ "required": false, "schema": { "type": "string", + "example": "test", "default": "test" } }, diff --git a/e2e/src/cats/cats.controller.ts b/e2e/src/cats/cats.controller.ts index 94e239a61..c568161b7 100644 --- a/e2e/src/cats/cats.controller.ts +++ b/e2e/src/cats/cats.controller.ts @@ -37,7 +37,8 @@ import { CatBreed } from './enums/cat-breed.enum'; name: 'header', required: false, description: 'Test', - schema: { default: 'test' } + schema: { default: 'test' }, + example: 'test' }) @Controller('cats') export class CatsController { diff --git a/lib/decorators/api-header.decorator.ts b/lib/decorators/api-header.decorator.ts index f13bd3e66..7a4b58a13 100644 --- a/lib/decorators/api-header.decorator.ts +++ b/lib/decorators/api-header.decorator.ts @@ -31,6 +31,7 @@ export function ApiHeader( examples: options.examples, schema: { type: 'string', + ...(options.example ? { example: options.example } : {}), ...(options.schema || {}) } }, diff --git a/test/explorer/swagger-explorer.spec.ts b/test/explorer/swagger-explorer.spec.ts index 3ff4d0bcc..fa18e9230 100644 --- a/test/explorer/swagger-explorer.spec.ts +++ b/test/explorer/swagger-explorer.spec.ts @@ -1382,6 +1382,16 @@ describe('SwaggerExplorer', () => { create(): Promise { return Promise.resolve(); } + + @ApiHeader({ + name: 'X-API-Version', + description: 'API version', + example: '2025-05-16' + }) + @Get('foos') + find2(): Promise { + return Promise.resolve([]); + } } it('should properly define headers', () => { @@ -1428,6 +1438,26 @@ describe('SwaggerExplorer', () => { } } ]); + expect(routes[2].root.parameters).toEqual([ + { + description: 'auth token', + name: 'Authorization', + in: 'header', + schema: { + default: 'default token', + type: 'string' + } + }, + { + description: 'API version', + name: 'X-API-Version', + in: 'header', + schema: { + type: 'string', + example: '2025-05-16' + } + } + ]); }); });