Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions e2e/api-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@
"required": false,
"schema": {
"type": "string",
"example": "test",
"default": "test"
}
},
Expand Down Expand Up @@ -416,6 +417,7 @@
"required": false,
"schema": {
"type": "string",
"example": "test",
"default": "test"
}
},
Expand Down Expand Up @@ -662,6 +664,7 @@
"required": false,
"schema": {
"type": "string",
"example": "test",
"default": "test"
}
},
Expand Down Expand Up @@ -739,6 +742,7 @@
"required": false,
"schema": {
"type": "string",
"example": "test",
"default": "test"
}
},
Expand Down Expand Up @@ -820,6 +824,7 @@
"required": false,
"schema": {
"type": "string",
"example": "test",
"default": "test"
}
},
Expand Down Expand Up @@ -1039,6 +1044,7 @@
"required": false,
"schema": {
"type": "string",
"example": "test",
"default": "test"
}
},
Expand Down Expand Up @@ -1113,6 +1119,7 @@
"required": false,
"schema": {
"type": "string",
"example": "test",
"default": "test"
}
},
Expand Down Expand Up @@ -1183,6 +1190,7 @@
"required": false,
"schema": {
"type": "string",
"example": "test",
"default": "test"
}
},
Expand Down Expand Up @@ -1269,6 +1277,7 @@
"required": false,
"schema": {
"type": "string",
"example": "test",
"default": "test"
}
},
Expand Down Expand Up @@ -1326,6 +1335,7 @@
"required": false,
"schema": {
"type": "string",
"example": "test",
"default": "test"
}
},
Expand Down Expand Up @@ -1396,6 +1406,7 @@
"required": false,
"schema": {
"type": "string",
"example": "test",
"default": "test"
}
},
Expand Down Expand Up @@ -1463,6 +1474,7 @@
"required": false,
"schema": {
"type": "string",
"example": "test",
"default": "test"
}
},
Expand Down Expand Up @@ -1542,6 +1554,7 @@
"required": false,
"schema": {
"type": "string",
"example": "test",
"default": "test"
}
},
Expand Down Expand Up @@ -1601,6 +1614,7 @@
"required": false,
"schema": {
"type": "string",
"example": "test",
"default": "test"
}
},
Expand Down
3 changes: 2 additions & 1 deletion e2e/src/cats/cats.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions lib/decorators/api-header.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function ApiHeader(
examples: options.examples,
schema: {
type: 'string',
...(options.example ? { example: options.example } : {}),
...(options.schema || {})
}
},
Expand Down
30 changes: 30 additions & 0 deletions test/explorer/swagger-explorer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,16 @@ describe('SwaggerExplorer', () => {
create(): Promise<any> {
return Promise.resolve();
}

@ApiHeader({
name: 'X-API-Version',
description: 'API version',
example: '2025-05-16'
})
@Get('foos')
find2(): Promise<Foo[]> {
return Promise.resolve([]);
}
}

it('should properly define headers', () => {
Expand Down Expand Up @@ -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'
}
}
]);
});
});

Expand Down