Skip to content

Commit

Permalink
fix(nestjs-redox): RedocOptions.logo and RedocOptions.tagGroups not w…
Browse files Browse the repository at this point in the history
…orking
  • Loading branch information
julianpoemp committed Jun 23, 2024
1 parent e01e6ff commit 9d8b1e0
Show file tree
Hide file tree
Showing 4 changed files with 967 additions and 349 deletions.
5 changes: 4 additions & 1 deletion apps/demo-express/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ async function bootstrap() {

const redocOptions: RedocOptions = {
requiredPropsFirst: true,
logo: {
url: "https://redocly.github.io/redoc/petstore-logo.png"
},
theme: {
sidebar: {
width: '222px',
},
},
};
}

const redoxOptions: NestJSRedoxOptions = {
useGlobalPrefix: true,
Expand Down
31 changes: 28 additions & 3 deletions libs/nestjs-redox/src/lib/nestjs-redox.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,17 @@ export class NestjsRedoxModule {
}
) {
let document: OpenAPIObject;
const documentURL = typeof documentOrURL === 'string' ? documentOrURL : undefined;
const documentURL =
typeof documentOrURL === 'string' ? documentOrURL : undefined;

const lazyBuildDocument = () => {
if (typeof documentOrURL === 'string') {
throw new Error('documentFactory is a string.');
}

return typeof documentOrURL === 'function'
? documentOrURL()
: documentOrURL;
? this.applyRedocExtensions(options.redocOptions, documentOrURL())
: this.applyRedocExtensions(options.redocOptions, documentOrURL);
};

const baseUrlForRedocUI = normalizeRelPath(`./${urlLastSubdirectory}/`);
Expand Down Expand Up @@ -293,4 +294,28 @@ export class NestjsRedoxModule {
res.header(header.name, header.value);
}
}

private static applyRedocExtensions(
redocOptions: RedocOptions | undefined,
swaggerSpec: OpenAPIObject
) {
if (redocOptions?.logo) {
const logo = swaggerSpec.info['x-logo'] ?? {};
swaggerSpec.info['x-logo'] = {
...logo,
url: logo['url'] ?? redocOptions.logo.url,
href: logo['href'] ?? redocOptions.logo.href,
backgroundColor:
logo['backgroundColor'] ?? redocOptions.logo.backgroundColor,
altText: logo['altText'] ?? redocOptions.logo.altText,
};
}

if (redocOptions?.tagGroups) {
swaggerSpec.info['x-tagGroups'] =
swaggerSpec.info['x-tagGroups'] ?? redocOptions.tagGroups;
}

return swaggerSpec;
}
}
Loading

0 comments on commit 9d8b1e0

Please sign in to comment.