MCPcopy Index your code
hub / github.com/nestjs/swagger / serveDefinitions

Method serveDefinitions

lib/swagger-module.ts:298–357  ·  view source on GitHub ↗
(
    httpAdapter: HttpServer,
    getBuiltDocument: () => OpenAPIObject,
    options: {
      jsonDocumentUrl: string;
      yamlDocumentUrl: string;
      swaggerOptions: SwaggerCustomOptions;
    },
    serveOptions: { serveJson: boolean; serveYaml: boolean }
  )

Source from the content-addressed store, hash-verified

296 }
297
298 protected static serveDefinitions(
299 httpAdapter: HttpServer,
300 getBuiltDocument: () => OpenAPIObject,
301 options: {
302 jsonDocumentUrl: string;
303 yamlDocumentUrl: string;
304 swaggerOptions: SwaggerCustomOptions;
305 },
306 serveOptions: { serveJson: boolean; serveYaml: boolean }
307 ) {
308 if (serveOptions.serveJson) {
309 httpAdapter.get(
310 normalizeRelPath(options.jsonDocumentUrl),
311 async (req, res) => {
312 res.type('application/json');
313 const document = getBuiltDocument();
314
315 const documentToSerialize = options.swaggerOptions
316 .patchDocumentOnRequest
317 ? await Promise.resolve(
318 options.swaggerOptions.patchDocumentOnRequest(
319 req,
320 res,
321 document
322 )
323 )
324 : document;
325
326 return res.send(JSON.stringify(documentToSerialize));
327 }
328 );
329 }
330
331 if (serveOptions.serveYaml) {
332 httpAdapter.get(
333 normalizeRelPath(options.yamlDocumentUrl),
334 async (req, res) => {
335 res.type('text/yaml');
336 const document = getBuiltDocument();
337
338 const documentToSerialize = options.swaggerOptions
339 .patchDocumentOnRequest
340 ? await Promise.resolve(
341 options.swaggerOptions.patchDocumentOnRequest(
342 req,
343 res,
344 document
345 )
346 )
347 : document;
348
349 const yamlDocument = jsyaml.dump(documentToSerialize, {
350 skipInvalid: true,
351 noRefs: true
352 });
353 return res.send(yamlDocument);
354 }
355 );

Callers 1

serveDocumentsMethod · 0.95

Calls 2

normalizeRelPathFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected