Skip to content

Commit

Permalink
Merge branch 'nestjs:master' into feat-global-paramters
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyTseng committed Dec 7, 2022
2 parents 866b731 + f4dc916 commit d0ef0fa
Show file tree
Hide file tree
Showing 5 changed files with 835 additions and 462 deletions.
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ jobs:
build:
working_directory: ~/nest
docker:
- image: cimg/node:17.9
- image: cimg/node:18.10
steps:
- checkout
- run:
name: Update NPM version
command: npm install -g npm@latest
command: 'sudo npm install -g npm@^8'
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
Expand All @@ -51,7 +51,7 @@ jobs:
unit_tests:
working_directory: ~/nest
docker:
- image: cimg/node:17.9
- image: cimg/node:18.10
steps:
- checkout
- *restore-cache
Expand All @@ -62,7 +62,7 @@ jobs:
e2e_tests:
working_directory: ~/nest
docker:
- image: cimg/node:17.9
- image: cimg/node:18.10
steps:
- checkout
- *restore-cache
Expand All @@ -81,4 +81,4 @@ workflows:
- e2e_tests:
requires:
- build


6 changes: 3 additions & 3 deletions lib/interfaces/swagger-custom-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export interface SwaggerCustomOptions {
explorer?: boolean;
swaggerOptions?: SwaggerUiOptions;
customCss?: string;
customCssUrl?: string;
customJs?: string;
customJsStr?: string;
customCssUrl?: string | string[];
customJs?: string | string[];
customJsStr?: string | string[];
customfavIcon?: string;
swaggerUrl?: string;
customSiteTitle?: string;
Expand Down
39 changes: 31 additions & 8 deletions lib/swagger-ui/swagger-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,33 @@ export function getSwaggerAssetsAbsoluteFSPath() {
return swaggerAssetsAbsoluteFSPath;
}

function toExternalScriptTag(url: string) {
return `<script src='${url}'></script>`;
}

function toInlineScriptTag(jsCode: string) {
return `<script>${jsCode}</script>`;
}

function toExternalStylesheetTag(url: string) {
return `<link href='${url}' rel='stylesheet'>`;
}

function toTags(
customCode: string | string[] | undefined,
toScript: (url: string) => string
) {
if (!customCode) {
return '';
}

if (typeof customCode === 'string') {
return toScript(customCode);
} else {
return customCode.map(toScript).join('\n');
}
}

/**
* Used to build swagger-ui custom html
*/
Expand All @@ -53,7 +80,7 @@ export function buildSwaggerHTML(
} = customOptions;

const favIconString = customfavIcon
? `<link rel="icon" href="${customfavIcon}" />`
? `<link rel='icon' href='${customfavIcon}' />`
: favIconHtml;

const explorerCss = explorer
Expand All @@ -64,15 +91,11 @@ export function buildSwaggerHTML(
.replace('<% explorerCss %>', explorerCss)
.replace('<% favIconString %>', favIconString)
.replace(/<% baseUrl %>/g, baseUrl)
.replace(
'<% customJs %>',
customJs ? `<script src="${customJs}"></script>` : ''
)
.replace(
'<% customJsStr %>', customJsStr ? `<script> ${customJsStr} </script>` : '')
.replace('<% customJs %>', toTags(customJs, toExternalScriptTag))
.replace('<% customJsStr %>', toTags(customJsStr, toInlineScriptTag))
.replace(
'<% customCssUrl %>',
customCssUrl ? `<link href="${customCssUrl}" rel="stylesheet">` : ''
toTags(customCssUrl, toExternalStylesheetTag)
)
.replace('<% title %>', customSiteTitle);
}

0 comments on commit d0ef0fa

Please sign in to comment.