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.
Asked
Active
Viewed 4,632 times
11

auerbachb
- 857
- 11
- 25
2 Answers
24
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.

Jay McDoniel
- 57,339
- 7
- 135
- 147
-
this works thanks I had seen https://github.com/nestjs/swagger/blob/ae3c35556522dc0dc2f42f769093861443ec5607/lib/interfaces/swagger-custom-options.interface.ts#L3, but wasn't sure that was the right key...I had tried passing the hash directly, which of course didn't work – auerbachb Nov 23 '20 at 19:30
0
To anyone trying @midopa's solution for FastifySwagger, pass the tagsSorter
and operationsSorter
values to uiConfig
instead of swaggerOptions
.
const doc = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('docs', app, doc, {
uiConfig: {
tagsSorter: 'alpha',
operationsSorter: 'alpha',
},
});
NOTE: This is for @nestjs/swagger version 6 or less. For v7 or above, swaggerOptions
will work just fine.

volf
- 83
- 1
- 10
-
-
The answer has been edited to add the version for which this solution was necessary. For @nestjs/swagger v7 or above, `swaggerOptions` will work. Thank you for directing my attention to this. – volf Jul 07 '23 at 02:41