Skip to content
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

Example removed from global parameter #3086

Closed
2 of 4 tasks
am-burban opened this issue Sep 25, 2024 · 2 comments
Closed
2 of 4 tasks

Example removed from global parameter #3086

am-burban opened this issue Sep 25, 2024 · 2 comments

Comments

@am-burban
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When adding a global parameter with an example, the example is not carried over to the generated spec (see Gist).

Probably related to #3031

Minimum reproduction code

https://gist.github.com/am-burban/5de53ea95c327896d297a26371fa7940

Steps to reproduce

No response

Expected behavior

Example is added to the generated spec

Package version

7.4.2

NestJS version

10.4.3

Node.js version

18.20.2

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue?

@chetanppatil
Copy link

@am-burban I tried updating to new version and found below things which you need to update.

Let's take example that you shared: https://gist.github.com/am-burban/5de53ea95c327896d297a26371fa7940

In this, to get example mentioned in addGlobalParameters in generated specs, you need to use it like below:

Option-1

  • If you do not want schema in globalParameter then remove this object and use example only as below.
const config = new DocumentBuilder()
    .setTitle('API Gateway')
    .setVersion(API_SPEC_VERSION)
    .addGlobalParameters(
      {
        in: 'header',
        required: false,
        name: REQUEST_ID_HEADER_NAME,
        description: 'Request ID used for debugging and tracing.',
        example: '5997c5f0-f9a6-4fdc-a4c3-53b850acca28',
      }
    )
    .build();

Option-2

  • If you wish to use schema, then remove example property from parent and use it under schema object, like below:
const config = new DocumentBuilder()
    .setTitle('API Gateway')
    .setVersion(API_SPEC_VERSION)
    .addGlobalParameters(
      {
        in: 'header',
        required: false,
        name: REQUEST_ID_HEADER_NAME,
        description: 'Request ID used for debugging and tracing.',
        schema: { type: 'string', minLength: 1, maxLength: 100, example: '5997c5f0-f9a6-4fdc-a4c3-53b850acca28' },
      }
    )
    .build();

Please try this, hope it solves your issue. I tried and both ways its working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants