From 83c3e8d57de865945c4d6d7dc2eeb4bbc257ece8 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 30 Jun 2023 13:48:25 +0200 Subject: [PATCH] refactor(@nestjs/swagger): rename the option to `patchDocumentOnRequest` Rename the option as pointed out here. https://github.com/nestjs/swagger/pull/2505#issuecomment-1614506935 --- e2e/express.e2e-spec.ts | 6 ++--- e2e/fastify.e2e-spec.ts | 6 ++--- e2e/manual-e2e.ts | 2 +- .../swagger-custom-options.interface.ts | 2 +- lib/swagger-module.ts | 24 +++++++++---------- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/e2e/express.e2e-spec.ts b/e2e/express.e2e-spec.ts index ec43a8488..7194de819 100644 --- a/e2e/express.e2e-spec.ts +++ b/e2e/express.e2e-spec.ts @@ -114,7 +114,7 @@ describe('Express Swagger', () => { SwaggerModule.setup('api', app, swaggerDocument, { jsonDocumentUrl: JSON_CUSTOM_URL, yamlDocumentUrl: YAML_CUSTOM_URL, - patchDocument: (req, res, document) => ({ + patchDocumentOnRequest: (req, res, document) => ({ ...document, info: { ...document.info, @@ -232,7 +232,7 @@ describe('Express Swagger', () => { customfavIcon: CUSTOM_FAVICON, customSiteTitle: CUSTOM_SITE_TITLE, customCssUrl: CUSTOM_CSS_URL, - patchDocument (req, res, document) { + patchDocumentOnRequest (req, res, document) { return { ...document, info: { @@ -301,7 +301,7 @@ describe('Express Swagger', () => { ); SwaggerModule.setup('/:customer/', app, swaggerDocument, { - patchDocument (req, res, document) { + patchDocumentOnRequest (req, res, document) { return { ...document, info: { diff --git a/e2e/fastify.e2e-spec.ts b/e2e/fastify.e2e-spec.ts index 4479b8eb5..432d3eb05 100644 --- a/e2e/fastify.e2e-spec.ts +++ b/e2e/fastify.e2e-spec.ts @@ -117,7 +117,7 @@ describe('Fastify Swagger', () => { SwaggerModule.setup('api', app, swaggerDocument, { jsonDocumentUrl: JSON_CUSTOM_URL, yamlDocumentUrl: YAML_CUSTOM_URL, - patchDocument: (req, res, document) => ({ + patchDocumentOnRequest: (req, res, document) => ({ ...document, info: { ...document.info, @@ -237,7 +237,7 @@ describe('Fastify Swagger', () => { customfavIcon: CUSTOM_FAVICON, customSiteTitle: CUSTOM_SITE_TITLE, customCssUrl: CUSTOM_CSS_URL, - patchDocument: (req, res, document) => ({ + patchDocumentOnRequest: (req, res, document) => ({ ...document, info: { ...document.info, @@ -318,7 +318,7 @@ describe('Fastify Swagger', () => { ); SwaggerModule.setup('/:tenantId/', app, swaggerDocument, { - patchDocument (req, res, document) { + patchDocumentOnRequest (req, res, document) { return { ...document, info: { diff --git a/e2e/manual-e2e.ts b/e2e/manual-e2e.ts index f5d43b75d..367df6cfa 100644 --- a/e2e/manual-e2e.ts +++ b/e2e/manual-e2e.ts @@ -124,7 +124,7 @@ async function bootstrap() { }); SwaggerModule.setup("/:tenantId/api-docs", app, document, { - patchDocument: (req, res, document1) => ({ + patchDocumentOnRequest: (req, res, document1) => ({ ...document1, info: { ...document1.info, diff --git a/lib/interfaces/swagger-custom-options.interface.ts b/lib/interfaces/swagger-custom-options.interface.ts index a35d805a5..584a96bb1 100644 --- a/lib/interfaces/swagger-custom-options.interface.ts +++ b/lib/interfaces/swagger-custom-options.interface.ts @@ -18,5 +18,5 @@ export interface SwaggerCustomOptions { urls?: Record<'url' | 'name', string>[]; jsonDocumentUrl?: string; yamlDocumentUrl?: string; - patchDocument?: (req: TRequest, res: TResponse, document: OpenAPIObject) => OpenAPIObject; + patchDocumentOnRequest?: (req: TRequest, res: TResponse, document: OpenAPIObject) => OpenAPIObject; } diff --git a/lib/swagger-module.ts b/lib/swagger-module.ts index d8be26859..a04c9bfdc 100644 --- a/lib/swagger-module.ts +++ b/lib/swagger-module.ts @@ -103,8 +103,8 @@ export class SwaggerModule { if (!document) { document = lazyBuildDocument(); - if (options.swaggerOptions.patchDocument) { - document = options.swaggerOptions.patchDocument(req, res, document); + if (options.swaggerOptions.patchDocumentOnRequest) { + document = options.swaggerOptions.patchDocumentOnRequest(req, res, document); } } @@ -131,8 +131,8 @@ export class SwaggerModule { if (!document) { document = lazyBuildDocument(); - if (options.swaggerOptions.patchDocument) { - document = options.swaggerOptions.patchDocument( + if (options.swaggerOptions.patchDocumentOnRequest) { + document = options.swaggerOptions.patchDocumentOnRequest( req, res, document @@ -163,8 +163,8 @@ export class SwaggerModule { if (!document) { document = lazyBuildDocument(); - if (options.swaggerOptions.patchDocument) { - document = options.swaggerOptions.patchDocument(req, res, document); + if (options.swaggerOptions.patchDocumentOnRequest) { + document = options.swaggerOptions.patchDocumentOnRequest(req, res, document); } } @@ -187,8 +187,8 @@ export class SwaggerModule { if (!document) { document = lazyBuildDocument(); - if (options.swaggerOptions.patchDocument) { - document = options.swaggerOptions.patchDocument(req, res, document); + if (options.swaggerOptions.patchDocumentOnRequest) { + document = options.swaggerOptions.patchDocumentOnRequest(req, res, document); } } @@ -220,8 +220,8 @@ export class SwaggerModule { if (!document) { document = lazyBuildDocument(); - if (options.swaggerOptions.patchDocument) { - document = options.swaggerOptions.patchDocument(req, res, document); + if (options.swaggerOptions.patchDocumentOnRequest) { + document = options.swaggerOptions.patchDocumentOnRequest(req, res, document); } } @@ -238,8 +238,8 @@ export class SwaggerModule { if (!document) { document = lazyBuildDocument(); - if (options.swaggerOptions.patchDocument) { - document = options.swaggerOptions.patchDocument(req, res, document); + if (options.swaggerOptions.patchDocumentOnRequest) { + document = options.swaggerOptions.patchDocumentOnRequest(req, res, document); } }