-
Notifications
You must be signed in to change notification settings - Fork 474
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
fix(plugin): allow the use of "uiConfig" options to fastify-swagger and Swagger UI #1341
Conversation
@@ -8,6 +8,7 @@ export interface SwaggerCustomOptions { | |||
swaggerUrl?: string; | |||
customSiteTitle?: string; | |||
validatorUrl?: string; | |||
uiConfig?: Record<string, any>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should define a separate options object for the fastify platform.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With just the uiConfig property (for now)?
export interface FastifySwaggerCustomOptions {
uiConfig?: Record<string, any>;
}
And how do you want to handle narrowing the options
type since we would have to do something along the lines of SwaggerCustomOptions | FastifySwaggerCustomOptions
:
public static setup(
path: string,
app: INestApplication,
document: OpenAPIObject,
options?: SwaggerCustomOptions | FastifySwaggerCustomOptions
) {
const httpAdapter = app.getHttpAdapter();
if (httpAdapter && httpAdapter.getType() === 'fastify') {
return this.setupFastify(
path,
httpAdapter,
document,
options as FastifySwaggerCustomOptions
);
}
return this.setupExpress(
path,
app,
document,
options as SwaggerCustomOptions
);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! Since we're about to introduce a new FastifySwaggerCustomOptions
type, I think we should rename the existing one (SwaggerCustomOptions
) to ExpressSwaggerCustomOptions
and define a union type SwaggerCustomOptions = ExpressSwaggerCustomOptions | FastifySwaggerCustomOptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kamilmysliwiec sorry, had a lot on my plate but I've done the split! :)
LGTM. Merged to 8.0.0 branch |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Using
@nestjs/swagger
with Fastify, you cannot pass theuiConfig
options atfastify-swagger
plugin registration.Issue Number: N/A
What is the new behavior?
You can pass on
uiConfig
as per fastify-swagger's documentation.Does this PR introduce a breaking change?
Other information
In order to get there, this PR adds a fourth argument to
setupFastify()
which is theoptions: SwaggerCustomOptions
object. This PR also adds theuiConfig?: Record<string, any>
property toSwaggerCustomOptions
as hint.With this update, we can make use of great features from Swagger UI such as authorization persistence (
uiConfig.persistAuthorization
) and showing the operation's id (uiConfig.displayOperationId
).