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

Support changing the OpenAPI document based on the request #2505

Merged
merged 6 commits into from
Jul 4, 2023

Conversation

botflux
Copy link
Contributor

@botflux botflux commented Jun 30, 2023

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?

It is impossible to patch the document after it is generated and before it is served.

Issue Number: #2502

What is the new behavior?

A new option patchDocument can be passed to SwaggerModule.setup.

SwaggerModule.setup("/:tenantId/api-docs", app, document, {
  patchDocument: (req: Request, res: Response, document1: OpenAPIObject) => ({
    ...document1,
    info: {
      ...document1.info,
      title: `${req.params.tenantId}'s API document`
    }
  })
})

Does this PR introduce a breaking change?

  • Yes
  • [ x ] No

Other information

@kamilmysliwiec
Copy link
Member

PR looks great! One minor thing - I'm wondering if we have any ideas other than patchDocument for the name of this function. Ideally, the name should indicate when the patching happens (on request) so it's clear to everyone that it will be called more than once (1 per request). Perhaps patchDocumentOnRequest? It's quite long, but I can't think of anything better. WDYT?

@botflux
Copy link
Contributor Author

botflux commented Jun 30, 2023

You are right, I'm changing it.
I think patchDocumentOnRequest is a good name.

botflux added a commit to botflux/docs.nestjs.com that referenced this pull request Jul 4, 2023
@kamilmysliwiec kamilmysliwiec merged commit dcfdf1b into nestjs:master Jul 4, 2023
1 check passed
@kamilmysliwiec
Copy link
Member

LGTM

kamilmysliwiec added a commit to nestjs/docs.nestjs.com that referenced this pull request Jul 4, 2023
docs(@nestjs/swagger): add `patchDocumentOnRequest` option based on nestjs/swagger#2505
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.

None yet

2 participants