Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NestJS Alphabetize Endpoints in SwaggerUI

This SO answer shows that SwaggerUi will sort endpoints alphabetically if it is passed apisSorter : "alpha" when instantiated. In NestJS the config options are passed in the SwaggerModule.createDocument. I cannot see where in the config eg here I can pass this.

like image 508
auerbachb Avatar asked Nov 23 '20 18:11

auerbachb


1 Answers

You can pass it as the fourth parameter to the SwaggerModule.setup method like so:

const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('docs', app, document, {
    swaggerOptions: {
      tagsSorter: 'alpha',
      operationsSorter: 'alpha',
    },
  });

swaggerOptions is untyped which is why you just have to know what you're passing. Found the answer in the discord server so hopefully that link doesn't expire.

like image 92
Jay McDoniel Avatar answered Sep 21 '22 19:09

Jay McDoniel