(
finalPath: string,
urlLastSubdirectory: string,
httpAdapter: HttpServer,
documentOrFactory: OpenAPIObject | (() => OpenAPIObject),
options: {
ui: boolean;
raw: boolean | Array<'json' | 'yaml'>;
jsonDocumentUrl: string;
yamlDocumentUrl: string;
swaggerOptions: SwaggerCustomOptions;
}
)
| 121 | } |
| 122 | |
| 123 | protected static serveDocuments( |
| 124 | finalPath: string, |
| 125 | urlLastSubdirectory: string, |
| 126 | httpAdapter: HttpServer, |
| 127 | documentOrFactory: OpenAPIObject | (() => OpenAPIObject), |
| 128 | options: { |
| 129 | ui: boolean; |
| 130 | raw: boolean | Array<'json' | 'yaml'>; |
| 131 | jsonDocumentUrl: string; |
| 132 | yamlDocumentUrl: string; |
| 133 | swaggerOptions: SwaggerCustomOptions; |
| 134 | } |
| 135 | ) { |
| 136 | let document: OpenAPIObject; |
| 137 | |
| 138 | const getBuiltDocument = () => { |
| 139 | if (!document) { |
| 140 | document = |
| 141 | typeof documentOrFactory === 'function' |
| 142 | ? documentOrFactory() |
| 143 | : documentOrFactory; |
| 144 | } |
| 145 | return document; |
| 146 | }; |
| 147 | |
| 148 | if (options.ui) { |
| 149 | this.serveSwaggerUi( |
| 150 | finalPath, |
| 151 | urlLastSubdirectory, |
| 152 | httpAdapter, |
| 153 | getBuiltDocument, |
| 154 | options.swaggerOptions |
| 155 | ); |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Serve JSON/YAML definitions based on the `raw` option: |
| 160 | * - `true`: Serve both JSON and YAML definitions. |
| 161 | * - `false`: Skip registering both JSON and YAML definitions. |
| 162 | * - `Array<'json' | 'yaml'>`: Serve only the specified formats (e.g., `['json']` to serve only JSON). |
| 163 | */ |
| 164 | if ( |
| 165 | options.raw === true || |
| 166 | (Array.isArray(options.raw) && options.raw.length > 0) |
| 167 | ) { |
| 168 | const serveJson = options.raw === true || options.raw.includes('json'); |
| 169 | const serveYaml = options.raw === true || options.raw.includes('yaml'); |
| 170 | |
| 171 | this.serveDefinitions(httpAdapter, getBuiltDocument, options, { |
| 172 | serveJson, |
| 173 | serveYaml |
| 174 | }); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | protected static serveSwaggerUi( |
| 179 | finalPath: string, |
no test coverage detected