Skip to content

Commit

Permalink
feat: make ReDoc version configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Märt Vaha committed Apr 5, 2021
1 parent 19937f6 commit 547131e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/interfaces/redocOptions.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export interface RedocOptions {
/** Version of ReDoc to use (e.g. next, latest, 2.0.0-rc.50), by default is latest */
redocVersion?: string;
/** Web site title (e.g: ReDoc documentation) */
title?: string;
/** Web site favicon URL */
Expand Down
1 change: 1 addition & 0 deletions src/model/options.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { OpenAPIObject } from '@nestjs/swagger';

export const schema = (document: OpenAPIObject) =>
Joi.object().keys({
redocVersion: Joi.string().default('latest'),
title: Joi.string()
.optional()
.default(document.info ? document.info.title : 'Swagger documentation'),
Expand Down
3 changes: 2 additions & 1 deletion src/redoc-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,14 @@ export class RedocModule {
},
});
// spread redoc options
const { title, favicon, theme, ...otherOptions } = options;
const { title, favicon, theme, redocVersion, ...otherOptions } = options;
// create render object
const renderData = {
data: {
title,
docUrl,
favicon,
redocVersion,
options: otherOptions,
...(theme && {
theme: {
Expand Down
2 changes: 1 addition & 1 deletion views/redoc.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<body>
<!-- we provide is specification here -->
<div id="redoc_container"></div>
<script src="https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js"> </script>
<script src="https://cdn.jsdelivr.net/npm/redoc@{{data.redocVersion}}/bundles/redoc.standalone.js"> </script>
<script>
let themeJSON = '{{{ toJSON data.theme }}}';
if (themeJSON === '') { themeJSON = undefined }
Expand Down

0 comments on commit 547131e

Please sign in to comment.