Skip to content

Commit

Permalink
chore: deprecate swagger ui enabled, use ui instead
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Dec 4, 2024
1 parent e579904 commit 675a027
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions e2e/express.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('Express Swagger', () => {
builder.build()
);
SwaggerModule.setup(SWAGGER_RELATIVE_URL, app, swaggerDocument, {
swaggerUiEnabled: false
ui: false
});

await app.init();
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('Express Swagger', () => {
builder.build()
);
SwaggerModule.setup(SWAGGER_RELATIVE_URL, app, swaggerDocument, {
swaggerUiEnabled: false,
ui: false,
raw: false
});

Expand Down
2 changes: 1 addition & 1 deletion e2e/fastify.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe('Fastify Swagger', () => {
builder.build()
);
SwaggerModule.setup(SWAGGER_RELATIVE_URL, app, swaggerDocument, {
swaggerUiEnabled: false,
ui: false,
raw: false
});

Expand Down
11 changes: 9 additions & 2 deletions lib/interfaces/swagger-custom-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ export interface SwaggerCustomOptions {

/**
* If `false`, the Swagger UI will not be served. Only API definitions (JSON and YAML)
* will be accessible (on `/{path}-json` and `/{path}-yaml`).
* To fully disable both the Swagger UI and API definitions, use `raw: false`.
* will be accessible (on `/{path}-json` and `/{path}-yaml`). To fully disable both the Swagger UI and API definitions, use `raw: false`.
* Default: `true`.
* @deprecated Use `ui` instead.
*/
swaggerUiEnabled?: boolean;

/**
* If `false`, the Swagger UI will not be served. Only API definitions (JSON and YAML)
* will be accessible (on `/{path}-json` and `/{path}-yaml`). To fully disable both the Swagger UI and API definitions, use `raw: false`.
* Default: `true`.
*/
ui?: boolean;

/**
* If `true`, raw definitions for all formats will be served.
* Alternatively, you can pass an array to specify the formats to be served, e.g., `raw: ['json']` to serve only JSON definitions.
Expand Down
10 changes: 5 additions & 5 deletions lib/swagger-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class SwaggerModule {
httpAdapter: HttpServer,
documentOrFactory: OpenAPIObject | (() => OpenAPIObject),
options: {
swaggerUiEnabled: boolean;
ui: boolean;
raw: boolean | Array<'json' | 'yaml'>;
jsonDocumentUrl: string;
yamlDocumentUrl: string;
Expand All @@ -104,7 +104,7 @@ export class SwaggerModule {
return document;
};

if (options.swaggerUiEnabled) {
if (options.ui) {
this.serveSwaggerUi(
finalPath,
urlLastSubdirectory,
Expand Down Expand Up @@ -308,7 +308,7 @@ export class SwaggerModule {
? `${validatedGlobalPrefix}${validatePath(options.yamlDocumentUrl)}`
: `${finalPath}-yaml`;

const swaggerUiEnabled = options?.swaggerUiEnabled ?? true;
const ui = options?.ui ?? options?.swaggerUiEnabled ?? true;
const raw = options?.raw ?? true;

const httpAdapter = app.getHttpAdapter();
Expand All @@ -319,15 +319,15 @@ export class SwaggerModule {
httpAdapter,
documentOrFactory,
{
swaggerUiEnabled,
ui,
raw,
jsonDocumentUrl: finalJSONDocumentPath,
yamlDocumentUrl: finalYAMLDocumentPath,
swaggerOptions: options || {}
}
);

if (swaggerUiEnabled) {
if (ui) {
SwaggerModule.serveStatic(finalPath, app, options?.customSwaggerUiPath);
/**
* Covers assets fetched through a relative path when Swagger url ends with a slash '/'.
Expand Down

0 comments on commit 675a027

Please sign in to comment.