Skip to content

Commit 4e0ee75

Browse files
Merge pull request #2972 from lucas-gregoire/patch-1
docs: improve documentation about Swagger setup options
2 parents 164ab78 + 9fea694 commit 4e0ee75

File tree

1 file changed

+97
-8
lines changed

1 file changed

+97
-8
lines changed

content/openapi/introduction.md

Lines changed: 97 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,112 @@ const document = SwaggerModule.createDocument(app, config, options);
131131

132132
#### Setup options
133133

134-
You can configure Swagger UI by passing the options object which fulfills the `ExpressSwaggerCustomOptions` (if you use express) interface as a fourth argument of the `SwaggerModule#setup` method.
134+
You can configure Swagger UI by passing the options object which fulfills the `SwaggerCustomOptions` interface as a fourth argument of the `SwaggerModule#setup` method.
135135

136136
```TypeScript
137-
export interface ExpressSwaggerCustomOptions {
137+
export interface SwaggerCustomOptions {
138+
/**
139+
* If `true`, Swagger resources paths will be prefixed by the global prefix set through `setGlobalPrefix()`.
140+
* Default: `false`.
141+
* @see https://docs.nestjs.com/faq/global-prefix
142+
*/
143+
useGlobalPrefix?: boolean;
144+
145+
/**
146+
* If `false`, only API definitions (JSON and YAML) will be served (on `/{path}-json` and `/{path}-yaml`).
147+
* This is particularly useful if you are already hosting a Swagger UI somewhere else and just want to serve API definitions.
148+
* Default: `true`.
149+
*/
150+
swaggerUiEnabled?: boolean;
151+
152+
/**
153+
* Url point the API definition to load in Swagger UI.
154+
*/
155+
swaggerUrl?: string;
156+
157+
/**
158+
* Path of the JSON API definition to serve.
159+
* Default: `<path>-json`.
160+
*/
161+
jsonDocumentUrl?: string;
162+
163+
/**
164+
* Path of the YAML API definition to serve.
165+
* Default: `<path>-json`.
166+
*/
167+
yamlDocumentUrl?: string;
168+
169+
/**
170+
* Hook allowing to alter the OpenAPI document before being served.
171+
* It's called after the document is generated and before it is served as JSON & YAML.
172+
*/
173+
patchDocumentOnRequest?: <TRequest = any, TResponse = any>(
174+
req: TRequest,
175+
res: TResponse,
176+
document: OpenAPIObject
177+
) => OpenAPIObject;
178+
179+
/**
180+
* If `true`, the selector of OpenAPI definitions is displayed in the Swagger UI interface.
181+
* Default: `false`.
182+
*/
138183
explorer?: boolean;
139-
swaggerOptions?: Record<string, any>;
184+
185+
/**
186+
* Additional Swagger UI options
187+
*/
188+
swaggerOptions?: SwaggerUiOptions;
189+
190+
/**
191+
* Custom CSS styles to inject in Swagger UI page.
192+
*/
140193
customCss?: string;
141-
customCssUrl?: string;
142-
customJs?: string;
194+
195+
/**
196+
* URL(s) of a custom CSS stylesheet to load in Swagger UI page.
197+
*/
198+
customCssUrl?: string | string[];
199+
200+
/**
201+
* URL(s) of custom JavaScript files to load in Swagger UI page.
202+
*/
203+
customJs?: string | string[];
204+
205+
/**
206+
* Custom JavaScript scripts to load in Swagger UI page.
207+
*/
208+
customJsStr?: string | string[];
209+
210+
/**
211+
* Custom favicon for Swagger UI page.
212+
*/
143213
customfavIcon?: string;
144-
customSwaggerUiPath?: string;
145-
swaggerUrl?: string;
214+
215+
/**
216+
* Custom title for Swagger UI page.
217+
*/
146218
customSiteTitle?: string;
219+
220+
/**
221+
* File system path (ex: ./node_modules/swagger-ui-dist) containing static Swagger UI assets.
222+
*/
223+
customSwaggerUiPath?: string;
224+
225+
/**
226+
* @deprecated This property has no effect.
227+
*/
147228
validatorUrl?: string;
229+
230+
/**
231+
* @deprecated This property has no effect.
232+
*/
148233
url?: string;
234+
235+
/**
236+
* @deprecated This property has no effect.
237+
*/
149238
urls?: Record<'url' | 'name', string>[];
150-
patchDocumentOnRequest?: <TRequest = any, TResponse = any> (req: TRequest, res: TResponse, document: OpenAPIObject) => OpenAPIObject;
239+
151240
}
152241
```
153242

0 commit comments

Comments
 (0)