Skip to content

feat(api-header): add example property to ApiHeader decorator #3449

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

leemhoon00
Copy link

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

When using the @ApiHeader decorator with the example field (not examples) on methods or controllers:

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

  @ApiHeader({
    name: 'test',
    example: 'example-data',
  })
  @Get()
  getHello() {
    console.log('Hello World');
  }
}

then

image

it is not applied

Issue Number: N/A

What is the new behavior?

image

example field are applied

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

According to OpenAPI 3.0 Parameter Object, example should be placed inside schema.

@leemhoon00 leemhoon00 marked this pull request as draft May 16, 2025 10:22
@leemhoon00 leemhoon00 marked this pull request as ready for review May 16, 2025 10:24
@kamilmysliwiec
Copy link
Member

Could you please update e2e tests too?

@leemhoon00
Copy link
Author

leemhoon00 commented May 16, 2025

Could you please update e2e tests too?

Thank you for the feedback.

From what I can see, the e2e tests don’t explicitly check for headers. Are we simply expected to:

  1. Add the example field in @ApiHeader in CatController,
@ApiHeader({
  name: 'header',
  required: false,
  description: 'Test',
  schema: { default: 'test' },
  example: 'test'
})
  1. Regenerate the api-spec.json, and commit it?

Or do we also need to include a validation check in validate-schema.e2e-spec.ts, like this?

expect(
    api.paths['/api/cats']['get']['parameters'][0]['schema']['example']
  ).toBe('test');

@@ -169,6 +169,17 @@ describe('Validate OpenAPI schema', () => {
);
expect(api.paths['/api/cats']['get']['tags']).toContain('tag1');
expect(api.paths['/api/cats']['get']['tags']).toContain('tag2');
expect(api.paths['/api/cats']['get']['parameters'][0]).toEqual({
name: 'header',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to check it here

@leemhoon00 leemhoon00 requested a review from kamilmysliwiec May 19, 2025 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants