Skip to content

Commit d826b87

Browse files
chore: improve wording
1 parent c50bdde commit d826b87

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

content/openapi/other-features.md

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ async function bootstrap() {
5858
.addTag('cats')
5959
.build();
6060

61-
const catDocumentFactory = () => SwaggerModule.createDocument(app, options, {
62-
include: [CatsModule],
63-
});
61+
const catDocumentFactory = () =>
62+
SwaggerModule.createDocument(app, options, {
63+
include: [CatsModule],
64+
});
6465
SwaggerModule.setup('api/cats', app, catDocumentFactory);
6566

6667
const secondOptions = new DocumentBuilder()
@@ -70,9 +71,10 @@ async function bootstrap() {
7071
.addTag('dogs')
7172
.build();
7273

73-
const dogDocumentFactory = () => SwaggerModule.createDocument(app, secondOptions, {
74-
include: [DogsModule],
75-
});
74+
const dogDocumentFactory = () =>
75+
SwaggerModule.createDocument(app, secondOptions, {
76+
include: [DogsModule],
77+
});
7678
SwaggerModule.setup('api/dogs', app, dogDocumentFactory);
7779

7880
await app.listen(process.env.PORT ?? 3000);
@@ -94,14 +96,14 @@ In turn, `http://localhost:3000/api/dogs` will expose the Swagger UI for dogs:
9496

9597
<figure><img src="/assets/swagger-dogs.png" /></figure>
9698

97-
#### Multiple specifications from dropdown in the explorer bar
99+
#### Dropdown in the explorer bar
98100

99-
To support multiple specifications from dropdown in the explorer bar, you need to use `explorer: true` and `swaggerOptions.urls` in `SwaggerCustomOption`.
101+
To enable support for multiple specifications in the dropdown menu of the explorer bar, you'll need to set `explorer: true` and configure `swaggerOptions.urls` in your `SwaggerCustomOptions`.
100102

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+
> info **Hint** Ensure that `swaggerOptions.urls` points to the JSON format of your Swagger documents! To specify the JSON document, use `jsonDocumentUrl` within `SwaggerCustomOptions`. For more setup options, check [here](/openapi/introduction#setup-options).
104+
105+
Here’s how to set up multiple specifications from a dropdown in the explorer bar:
103106

104-
You can setup multiple specifications from dropdown in the explorer barsupport as shown below
105107
```typescript
106108
import { NestFactory } from '@nestjs/core';
107109
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
@@ -112,17 +114,19 @@ import { DogsModule } from './dogs/dogs.module';
112114
async function bootstrap() {
113115
const app = await NestFactory.create(AppModule);
114116

117+
// Main API options
115118
const options = new DocumentBuilder()
116-
.setTitle('Multiple specifications example')
117-
.setDescription('The multiple specifications description')
119+
.setTitle('Multiple Specifications Example')
120+
.setDescription('Description for multiple specifications')
118121
.setVersion('1.0')
119122
.build();
120123

124+
// Create main API document
121125
const document = SwaggerModule.createDocument(app, options);
126+
127+
// Setup main API Swagger UI with dropdown support
122128
SwaggerModule.setup('api', app, document, {
123-
// This option is set to 'true' for the dropdown to be visible.
124129
explorer: true,
125-
126130
swaggerOptions: {
127131
urls: [
128132
{
@@ -142,35 +146,46 @@ async function bootstrap() {
142146
jsonDocumentUrl: '/api/swagger.json',
143147
});
144148

149+
// Cats API options
145150
const catOptions = new DocumentBuilder()
146-
.setTitle('Cats example')
147-
.setDescription('The cats API description')
151+
.setTitle('Cats Example')
152+
.setDescription('Description for the Cats API')
148153
.setVersion('1.0')
149154
.addTag('cats')
150155
.build();
151156

152-
const catDocument = SwaggerModule.createDocument(app, options, {
157+
// Create Cats API document
158+
const catDocument = SwaggerModule.createDocument(app, catOptions, {
153159
include: [CatsModule],
154160
});
161+
162+
// Setup Cats API Swagger UI
155163
SwaggerModule.setup('api/cats', app, catDocument, {
156164
jsonDocumentUrl: '/api/cats/swagger.json',
157165
});
158166

167+
// Dogs API options
159168
const dogOptions = new DocumentBuilder()
160-
.setTitle('Dogs example')
161-
.setDescription('The dogs API description')
169+
.setTitle('Dogs Example')
170+
.setDescription('Description for the Dogs API')
162171
.setVersion('1.0')
163172
.addTag('dogs')
164173
.build();
165174

175+
// Create Dogs API document
166176
const dogDocument = SwaggerModule.createDocument(app, dogOptions, {
167177
include: [DogsModule],
168178
});
179+
180+
// Setup Dogs API Swagger UI
169181
SwaggerModule.setup('api/dogs', app, dogDocument, {
170182
jsonDocumentUrl: '/api/dogs/swagger.json',
171183
});
172184

173185
await app.listen(3000);
174186
}
187+
175188
bootstrap();
176189
```
190+
191+
In this example, we set up a main API along with separate specifications for Cats and Dogs, each accessible from the dropdown in the explorer bar.

0 commit comments

Comments
 (0)