Skip to content

Commit

Permalink
feat: add support for x-tagGroups ext
Browse files Browse the repository at this point in the history
  • Loading branch information
UlrichFrancomme committed Nov 11, 2020
1 parent 0ecc436 commit ba66195
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/interfaces/redocDocument.interface.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { OpenAPIObject } from '@nestjs/swagger';
import { LogoOptions } from './redocOptions.interface';
import { LogoOptions, TagGroupOptions } from './redocOptions.interface';

export interface RedocDocument extends Partial<OpenAPIObject> {
info: OpenAPIObject['info'] & {
'x-logo'?: LogoOptions;
};
'x-tagGroups': TagGroupOptions[];
}
10 changes: 10 additions & 0 deletions src/interfaces/redocOptions.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export interface RedocOptions {
// If auth is enabled but no password is provided the default value is "123"
password: string;
};

/** Vendor extensions */

/** If set, group tags in categories in the side menu. Tags not added to a group will not be displayed. */
tagGroups?: TagGroupOptions[];
}

export interface LogoOptions {
Expand All @@ -61,3 +66,8 @@ export interface LogoOptions {
/** href tag for logo, it defaults to the one used in your API spec */
href?: string;
}

export interface TagGroupOptions {
name: string;
tags: string[];
}
8 changes: 8 additions & 0 deletions src/model/options.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,12 @@ export const schema = (document: OpenAPIObject) =>
user: Joi.string().default('admin'),
password: Joi.string().default('123'),
},
tagGroups: Joi.array()
.items(
Joi.object({
name: Joi.string(),
tags: Joi.array().items(Joi.string()),
})
)
.optional(),
});
6 changes: 6 additions & 0 deletions src/redoc-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import pathModule from 'path';
import { resolve } from 'url';
import { LogoOptions, RedocDocument, RedocOptions } from './interfaces';
import { schema } from './model/options.model';

export class RedocModule {
/**
* Setup ReDoc frontend
Expand Down Expand Up @@ -173,6 +174,11 @@ export class RedocModule {
const logoOption: Partial<LogoOptions> = { ...options.logo };
document.info['x-logo'] = logoOption;
}

if (options.tagGroups) {
document['x-tagGroups'] = options.tagGroups;
}

return document;
}
}

0 comments on commit ba66195

Please sign in to comment.