Skip to content

Commit 6e574cd

Browse files
authored
docs: update swagger-other-features docs
1 parent 164ab78 commit 6e574cd

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

content/openapi/other-features.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,84 @@ Navigate to `http://localhost:3000/api/cats` to see the Swagger UI for cats:
9393
In turn, `http://localhost:3000/api/dogs` will expose the Swagger UI for dogs:
9494

9595
<figure><img src="/assets/swagger-dogs.png" /></figure>
96+
97+
#### Multiple specifications from dropdown in the explorer bar
98+
99+
To support multiple specifications from dropdown in the explorer bar, you need to use `explorer: true` and `swaggerOptions.urls` in `SwaggerCustomOption`.
100+
101+
> info **Tip** `swaggerOptions.urls` must use the url of the swagger document in json format! To use json for specifications, use `jsonDocumentUrl` in `SwaggerCustomOption`.
102+
more setup options [here](/openapi/introduction#setup-options)
103+
104+
You can setup multiple specifications from dropdown in the explorer barsupport as shown below
105+
```typescript
106+
import { NestFactory } from '@nestjs/core';
107+
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
108+
import { AppModule } from './app.module';
109+
import { CatsModule } from './cats/cats.module';
110+
import { DogsModule } from './dogs/dogs.module';
111+
112+
async function bootstrap() {
113+
const app = await NestFactory.create(AppModule);
114+
115+
const options = new DocumentBuilder()
116+
.setTitle('Multiple specifications example')
117+
.setDescription('The multiple specifications description')
118+
.setVersion('1.0')
119+
.build();
120+
121+
const document = SwaggerModule.createDocument(app, options);
122+
SwaggerModule.setup('api', app, document, {
123+
// This option is set to 'true' for the dropdown to be visible.
124+
explorer: true,
125+
126+
swaggerOptions: {
127+
urls: [
128+
{
129+
name: '1. API',
130+
url: 'api/swagger.json',
131+
},
132+
{
133+
name: '2. Cats API',
134+
url: 'api/cats/swagger.json',
135+
},
136+
{
137+
name: '3. Dogs API',
138+
url: 'api/dogs/swagger.json',
139+
},
140+
],
141+
},
142+
jsonDocumentUrl: '/api/swagger.json',
143+
});
144+
145+
const catOptions = new DocumentBuilder()
146+
.setTitle('Cats example')
147+
.setDescription('The cats API description')
148+
.setVersion('1.0')
149+
.addTag('cats')
150+
.build();
151+
152+
const catDocument = SwaggerModule.createDocument(app, options, {
153+
include: [CatsModule],
154+
});
155+
SwaggerModule.setup('api/cats', app, catDocument, {
156+
jsonDocumentUrl: '/api/cats/swagger.json',
157+
});
158+
159+
const dogOptions = new DocumentBuilder()
160+
.setTitle('Dogs example')
161+
.setDescription('The dogs API description')
162+
.setVersion('1.0')
163+
.addTag('dogs')
164+
.build();
165+
166+
const dogDocument = SwaggerModule.createDocument(app, dogOptions, {
167+
include: [DogsModule],
168+
});
169+
SwaggerModule.setup('api/dogs', app, dogDocument, {
170+
jsonDocumentUrl: '/api/dogs/swagger.json',
171+
});
172+
173+
await app.listen(3000);
174+
}
175+
bootstrap();
176+
```

0 commit comments

Comments
 (0)