MCPcopy
hub / github.com/nestjs/swagger / createDocument

Method createDocument

lib/swagger-module.ts:42–89  ·  view source on GitHub ↗
(
    app: INestApplication,
    config: Omit<OpenAPIObject, 'paths'>,
    options: SwaggerDocumentOptions = {}
  )

Source from the content-addressed store, hash-verified

40 }
41
42 public static createDocument(
43 app: INestApplication,
44 config: Omit<OpenAPIObject, 'paths'>,
45 options: SwaggerDocumentOptions = {}
46 ): OpenAPIObject {
47 const swaggerScanner = new SwaggerScanner();
48 const document = swaggerScanner.scanApplication(app, options);
49 const { webhooks: configWebhooks, ...configWithoutWebhooks } =
50 config as OpenAPIObject;
51
52 document.components = assignTwoLevelsDeep(
53 {},
54 config.components,
55 document.components
56 );
57 const {
58 webhooks: scannedWebhooks,
59 webhookPaths,
60 ...documentWithoutWebhooks
61 } = document as OpenAPIObject & {
62 webhookPaths?: OpenAPIObject['paths'];
63 };
64 const mergedWebhooks = SwaggerModule.mergeWebhooks(
65 configWebhooks,
66 scannedWebhooks
67 );
68 const shouldIncludeWebhooks = isOas31OrLater(config.openapi ?? '3.0.0');
69 const baseDocument: OpenAPIObject = {
70 openapi: '3.0.0',
71 paths: {},
72 ...configWithoutWebhooks,
73 ...documentWithoutWebhooks
74 };
75
76 if (shouldIncludeWebhooks) {
77 return {
78 ...baseDocument,
79 ...(mergedWebhooks ? { webhooks: mergedWebhooks } : {})
80 };
81 }
82
83 return {
84 ...baseDocument,
85 paths: webhookPaths
86 ? assignTwoLevelsDeep({}, baseDocument.paths || {}, webhookPaths)
87 : baseDocument.paths
88 };
89 }
90
91 public static async loadPluginMetadata(
92 metadataFn: () => Promise<Record<string, any>>

Callers 5

bootstrapFunction · 0.80

Calls 4

scanApplicationMethod · 0.95
assignTwoLevelsDeepFunction · 0.90
isOas31OrLaterFunction · 0.90
mergeWebhooksMethod · 0.80

Tested by

no test coverage detected