Skip to content

Commit

Permalink
fix: patch document on every request #2547
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Aug 7, 2023
1 parent 062dcb6 commit 17371a6
Showing 1 changed file with 51 additions and 28 deletions.
79 changes: 51 additions & 28 deletions lib/swagger-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import {
import { assignTwoLevelsDeep } from './utils/assign-two-levels-deep';
import { getGlobalPrefix } from './utils/get-global-prefix';
import { normalizeRelPath } from './utils/normalize-rel-path';
import { resolvePath } from './utils/resolve-path.util';
import { validateGlobalPrefix } from './utils/validate-global-prefix.util';
import { validatePath } from './utils/validate-path.util';
import { resolvePath } from './utils/resolve-path.util';

export class SwaggerModule {
private static readonly metadataLoader = new MetadataLoader();
Expand Down Expand Up @@ -54,7 +54,11 @@ export class SwaggerModule {
return this.metadataLoader.load(metadata);
}

private static serveStatic(finalPath: string, app: INestApplication, customStaticPath?: string) {
private static serveStatic(
finalPath: string,
app: INestApplication,
customStaticPath?: string
) {
const httpAdapter = app.getHttpAdapter();

// See <https://github.com/nestjs/swagger/issues/2543>
Expand All @@ -69,10 +73,9 @@ export class SwaggerModule {
decorateReply: false
});
} else {
(app as NestExpressApplication).useStaticAssets(
swaggerAssetsPath,
{ prefix: finalPath }
);
(app as NestExpressApplication).useStaticAssets(swaggerAssetsPath, {
prefix: finalPath
});
}
}

Expand Down Expand Up @@ -107,10 +110,14 @@ export class SwaggerModule {

if (!document) {
document = lazyBuildDocument();
}

if (options.swaggerOptions.patchDocumentOnRequest) {
document = options.swaggerOptions.patchDocumentOnRequest(req, res, document);
}
if (options.swaggerOptions.patchDocumentOnRequest) {
document = options.swaggerOptions.patchDocumentOnRequest(
req,
res,
document
);
}

if (!swaggerInitJS) {
Expand All @@ -135,14 +142,14 @@ export class SwaggerModule {

if (!document) {
document = lazyBuildDocument();
}

if (options.swaggerOptions.patchDocumentOnRequest) {
document = options.swaggerOptions.patchDocumentOnRequest(
req,
res,
document
);
}
if (options.swaggerOptions.patchDocumentOnRequest) {
document = options.swaggerOptions.patchDocumentOnRequest(
req,
res,
document
);
}

if (!swaggerInitJS) {
Expand All @@ -167,10 +174,14 @@ export class SwaggerModule {

if (!document) {
document = lazyBuildDocument();
}

if (options.swaggerOptions.patchDocumentOnRequest) {
document = options.swaggerOptions.patchDocumentOnRequest(req, res, document);
}
if (options.swaggerOptions.patchDocumentOnRequest) {
document = options.swaggerOptions.patchDocumentOnRequest(
req,
res,
document
);
}

if (!html) {
Expand All @@ -191,10 +202,14 @@ export class SwaggerModule {

if (!document) {
document = lazyBuildDocument();
}

if (options.swaggerOptions.patchDocumentOnRequest) {
document = options.swaggerOptions.patchDocumentOnRequest(req, res, document);
}
if (options.swaggerOptions.patchDocumentOnRequest) {
document = options.swaggerOptions.patchDocumentOnRequest(
req,
res,
document
);
}

if (!html) {
Expand Down Expand Up @@ -224,10 +239,14 @@ export class SwaggerModule {

if (!document) {
document = lazyBuildDocument();
}

if (options.swaggerOptions.patchDocumentOnRequest) {
document = options.swaggerOptions.patchDocumentOnRequest(req, res, document);
}
if (options.swaggerOptions.patchDocumentOnRequest) {
document = options.swaggerOptions.patchDocumentOnRequest(
req,
res,
document
);
}

if (!jsonDocument) {
Expand All @@ -242,10 +261,14 @@ export class SwaggerModule {

if (!document) {
document = lazyBuildDocument();
}

if (options.swaggerOptions.patchDocumentOnRequest) {
document = options.swaggerOptions.patchDocumentOnRequest(req, res, document);
}
if (options.swaggerOptions.patchDocumentOnRequest) {
document = options.swaggerOptions.patchDocumentOnRequest(
req,
res,
document
);
}

if (!yamlDocument) {
Expand Down

0 comments on commit 17371a6

Please sign in to comment.