(
app: INestApplication,
config: Omit<OpenAPIObject, 'paths'>,
options: SwaggerDocumentOptions = {}
)
| 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>> |
no test coverage detected