@loopback/rest-explorer 3.0.6 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,53 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.3.0](https://github.com/strongloop/loopback-next/compare/@loopback/rest-explorer@3.2.1...@loopback/rest-explorer@3.3.0) (2021-05-03)
7
+
8
+
9
+ ### Features
10
+
11
+ * support node v16 ([ac99415](https://github.com/strongloop/loopback-next/commit/ac994154543bde22b4482ba98813351656db1b55))
12
+
13
+
14
+
15
+
16
+
17
+ ## [3.2.1](https://github.com/strongloop/loopback-next/compare/@loopback/rest-explorer@3.2.0...@loopback/rest-explorer@3.2.1) (2021-04-06)
18
+
19
+ **Note:** Version bump only for package @loopback/rest-explorer
20
+
21
+
22
+
23
+
24
+
25
+ # [3.2.0](https://github.com/strongloop/loopback-next/compare/@loopback/rest-explorer@3.1.0...@loopback/rest-explorer@3.2.0) (2021-03-18)
26
+
27
+
28
+ ### Features
29
+
30
+ * update package-lock.json to v2 consistently ([dfc3fbd](https://github.com/strongloop/loopback-next/commit/dfc3fbdae0c9ca9f34c64154a471bef22d5ac6b7))
31
+
32
+
33
+
34
+
35
+
36
+ # [3.1.0](https://github.com/strongloop/loopback-next/compare/@loopback/rest-explorer@3.0.6...@loopback/rest-explorer@3.1.0) (2021-02-09)
37
+
38
+
39
+ ### Bug Fixes
40
+
41
+ * prettier README ([1fc462e](https://github.com/strongloop/loopback-next/commit/1fc462e8065b6ef420d3be51273d18e4c59d986b))
42
+
43
+
44
+ ### Features
45
+
46
+ * **cli:** add graphql example ([6e53690](https://github.com/strongloop/loopback-next/commit/6e536904cd495a6d9d2d34bf9d184a2fa56c7bb2))
47
+ * add explorer indexTemplatePath customization ([070e0c9](https://github.com/strongloop/loopback-next/commit/070e0c9901a338204503006f6e8de749b39f8651))
48
+
49
+
50
+
51
+
52
+
6
53
  ## [3.0.6](https://github.com/strongloop/loopback-next/compare/@loopback/rest-explorer@3.0.5...@loopback/rest-explorer@3.0.6) (2021-01-21)
7
54
 
8
55
  **Note:** Version bump only for package @loopback/rest-explorer
package/README.md CHANGED
@@ -172,6 +172,26 @@ When the application runs, the explorer template will load the
172
172
  Here is a repository that contains popular Swagger-UI themes:
173
173
  https://github.com/ostranme/swagger-ui-themes.
174
174
 
175
+ ### Overriding the Swagger UI index.html
176
+
177
+ For more flexibility, the `indexTemplatePath` property can be used to allow full
178
+ customization of
179
+ [Swagger UI configuration options](https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/).
180
+
181
+ `indexTemplatePath` should be an absolute path to a .html.ejs template.
182
+
183
+ To get started,
184
+ [download the default index.html.ejs](https://github.com/strongloop/loopback-next/blob/master/packages/rest-explorer/templates/index.html.ejs),
185
+ add /explorer/index.html.ejs to your project, and update the configuration:
186
+
187
+ ```ts
188
+ this.configure(RestExplorerBindings.COMPONENT).to({
189
+ // For example, create a directory "explorer" at the same level
190
+ // as "src" and "node_modules" in your applciation structure
191
+ indexTemplatePath: path.resolve(__dirname, '../explorer/index.html.ejs'),
192
+ });
193
+ ```
194
+
175
195
  ## Contributions
176
196
 
177
197
  - [Guidelines](https://github.com/strongloop/loopback-next/blob/master/docs/CONTRIBUTING.md)
@@ -1 +1 @@
1
- {"version":3,"file":"rest-explorer.component.js","sourceRoot":"","sources":["../src/rest-explorer.component.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,uCAAuC;AACvC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAOwB;AACxB,yCAAgF;AAChF,yEAA8D;AAC9D,6DAA0D;AAG1D,MAAM,SAAS,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAE7C;;GAEG;AAEH,IAAa,qBAAqB,GAAlC,MAAa,qBAAqB;IAChC,YAEU,WAA4B,EAEpC,qBAAyC,EAAE;;QAFn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AW,CAAC,GAAG,CAAC,EAAE,yCAAoB,CAAC,SAAS,CAAC,GAAG,EAAC,EAAC,CAAC;IAGvE,mBAAA,aAAM,CAAC,mBAAY,CAAC,oBAAoB,CAAC,CAAA;IAEzC,mBAAA,aAAM,EAAE,CAAA;6CADY,sBAAe;GAH3B,qBAAqB,CA0CjC;AA1CY,sDAAqB"}
@@ -1,4 +1,4 @@
1
- import { OpenApiSpecForm, RequestContext, RestServer } from '@loopback/rest';
1
+ import { OpenApiSpecForm, RequestContext, RestServer, RestServerConfig } from '@loopback/rest';
2
2
  import { RestExplorerConfig } from './rest-explorer.types';
3
3
  export declare class ExplorerController {
4
4
  private serverBasePath;
@@ -9,7 +9,8 @@ export declare class ExplorerController {
9
9
  private openApiSpecUrl;
10
10
  private useSelfHostedSpec;
11
11
  private swaggerThemeFile;
12
- constructor(restConfig: (Partial<import("@loopback/rest").RestServerResolvedOptions> & import("@loopback/http-server").HttpOptions) | (Partial<import("@loopback/rest").RestServerResolvedOptions> & import("@loopback/http-server").HttpsOptions) | undefined, explorerConfig: RestExplorerConfig | undefined, serverBasePath: string, restServer: RestServer, requestContext: RequestContext);
12
+ private indexTemplatePath;
13
+ constructor(restConfig: RestServerConfig | undefined, explorerConfig: RestExplorerConfig | undefined, serverBasePath: string, restServer: RestServer, requestContext: RequestContext);
13
14
  indexRedirect(): void;
14
15
  index(): void;
15
16
  spec(): Promise<import("@loopback/rest").OpenAPIObject>;
@@ -12,19 +12,20 @@ const ejs_1 = tslib_1.__importDefault(require("ejs"));
12
12
  const fs_1 = tslib_1.__importDefault(require("fs"));
13
13
  const path_1 = tslib_1.__importDefault(require("path"));
14
14
  const rest_explorer_keys_1 = require("./rest-explorer.keys");
15
- // TODO(bajtos) Allow users to customize the template
16
- const indexHtml = path_1.default.resolve(__dirname, '../templates/index.html.ejs');
17
- const template = fs_1.default.readFileSync(indexHtml, 'utf-8');
18
- const templateFn = ejs_1.default.compile(template);
15
+ let prevIndexTemplatePath;
16
+ let templateFn;
19
17
  let ExplorerController = class ExplorerController {
20
18
  constructor(restConfig = {}, explorerConfig = {}, serverBasePath, restServer, requestContext) {
21
- var _a;
19
+ var _a, _b;
22
20
  this.serverBasePath = serverBasePath;
23
21
  this.restServer = restServer;
24
22
  this.requestContext = requestContext;
25
23
  this.useSelfHostedSpec = explorerConfig.useSelfHostedSpec !== false;
26
24
  this.openApiSpecUrl = this.getOpenApiSpecUrl(restConfig);
27
- this.swaggerThemeFile = (_a = explorerConfig.swaggerThemeFile) !== null && _a !== void 0 ? _a : './swagger-ui.css';
25
+ this.swaggerThemeFile =
26
+ (_a = explorerConfig.swaggerThemeFile) !== null && _a !== void 0 ? _a : './swagger-ui.css';
27
+ this.indexTemplatePath =
28
+ (_b = explorerConfig.indexTemplatePath) !== null && _b !== void 0 ? _b : path_1.default.resolve(__dirname, '../templates/index.html.ejs');
28
29
  }
29
30
  indexRedirect() {
30
31
  const { request, response } = this.requestContext;
@@ -59,6 +60,11 @@ let ExplorerController = class ExplorerController {
59
60
  openApiSpecUrl,
60
61
  swaggerThemeFile,
61
62
  };
63
+ if (prevIndexTemplatePath !== this.indexTemplatePath) {
64
+ const template = fs_1.default.readFileSync(this.indexTemplatePath, 'utf-8');
65
+ templateFn = ejs_1.default.compile(template);
66
+ prevIndexTemplatePath = this.indexTemplatePath;
67
+ }
62
68
  const homePage = templateFn(data);
63
69
  this.requestContext.response
64
70
  .status(200)
@@ -1 +1 @@
1
- {"version":3,"file":"rest-explorer.controller.js","sourceRoot":"","sources":["../src/rest-explorer.controller.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,uCAAuC;AACvC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAA8C;AAC9C,yCAMwB;AACxB,sDAAsB;AACtB,oDAAoB;AACpB,wDAAwB;AACxB,6DAA0D;AAG1D,qDAAqD;AACrD,MAAM,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,6BAA6B,CAAC,CAAC;AACzE,MAAM,QA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,MAAA,aAAa,CAAC,eAAe,mCAAI,EAAE,CAAC;QAC5D,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CACrD,eAAe,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CACpC,CAAC;QACF,OAAO,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,eAAe,CAAC;IACrC,CAAC;CACF,CAAA;AAhGiB,uCAAoB,GAAG,cAAc,CAAC;AACtC,+BAAY,GAAoB,MAAM,CAAC,MAAM,CAAC;IAC5D,OAAO,EAAE,OAAO;IAChB,MAAM,EAAE,MAAM;CACf,CAAC,CAAC;AALQ,kBAAkB;IAa1B,mBAAA,aAAM,CAAC,mBAAY,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAA;IAE7C,mBAAA,aAAM,CAAC,EAAC,WAAW,EAAE,yCAAoB,CAAC,SAAS,EAAC,CAAC,CAAA;IAErD,mBAAA,aAAM,CAAC,mBAAY,CAAC,SAAS,CAAC,CAAA;IAC9B,mBAAA,aAAM,CAAC,mBAAY,CAAC,MAAM,CAAC,CAAA;IAC3B,mBAAA,aAAM,CAAC,mBAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;qEADe,iBAAU;QACA,qBAAc;GAnBhE,kBAAkB,CAiG9B;AAjGY,gDAAkB;AAmG/B,SAAS,eAAe,CAAC,OAAwB;IAC/C,OAAO,CACL,OAAO,CAAC,OAAO,KAAK,kBAAkB,CAAC,YAAY,CAAC,OAAO;QAC3D,OAAO,CAAC,MAAM,KAAK,kBAAkB,CAAC,YAAY,CAAC,MAAM,CAC1D,CAAC;AACJ,CAAC"}
@@ -24,4 +24,5 @@ export declare type RestExplorerConfig = {
24
24
  */
25
25
  useSelfHostedSpec?: false;
26
26
  swaggerThemeFile?: string;
27
+ indexTemplatePath?: string;
27
28
  };
package/package.json CHANGED
@@ -1,11 +1,24 @@
1
1
  {
2
2
  "name": "@loopback/rest-explorer",
3
- "version": "3.0.6",
4
3
  "description": "LoopBack's API Explorer",
4
+ "version": "3.3.0",
5
+ "keywords": [
6
+ "LoopBack",
7
+ "Explorer",
8
+ "Swagger"
9
+ ],
10
+ "license": "MIT",
5
11
  "main": "dist/index.js",
6
12
  "types": "dist/index.d.ts",
13
+ "author": "IBM Corp.",
14
+ "copyright.owner": "IBM Corp.",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/strongloop/loopback-next.git",
18
+ "directory": "packages/rest-explorer"
19
+ },
7
20
  "engines": {
8
- "node": "^10.16 || 12 || 14 || 15"
21
+ "node": "^10.16 || 12 || 14 || 16"
9
22
  },
10
23
  "scripts": {
11
24
  "build": "lb-tsc",
@@ -14,37 +27,9 @@
14
27
  "test": "lb-mocha \"dist/__tests__/**/*.js\"",
15
28
  "verify": "npm pack && tar xf loopback-explorer*.tgz && tree package && npm run clean"
16
29
  },
17
- "author": "IBM Corp.",
18
- "copyright.owner": "IBM Corp.",
19
- "license": "MIT",
20
30
  "publishConfig": {
21
31
  "access": "public"
22
32
  },
23
- "peerDependencies": {
24
- "@loopback/core": "^2.14.0",
25
- "@loopback/rest": "^9.1.2"
26
- },
27
- "dependencies": {
28
- "ejs": "^3.1.5",
29
- "swagger-ui-dist": "3.38.0",
30
- "tslib": "^2.0.3"
31
- },
32
- "devDependencies": {
33
- "@loopback/build": "^6.2.9",
34
- "@loopback/core": "^2.14.0",
35
- "@loopback/eslint-config": "^10.0.5",
36
- "@loopback/rest": "^9.1.2",
37
- "@loopback/testlab": "^3.2.11",
38
- "@types/ejs": "^3.0.5",
39
- "@types/express": "^4.17.11",
40
- "@types/node": "^10.17.35",
41
- "express": "^4.17.1"
42
- },
43
- "keywords": [
44
- "LoopBack",
45
- "Explorer",
46
- "Swagger"
47
- ],
48
33
  "files": [
49
34
  "README.md",
50
35
  "dist",
@@ -52,10 +37,25 @@
52
37
  "!*/__tests__",
53
38
  "templates"
54
39
  ],
55
- "repository": {
56
- "type": "git",
57
- "url": "https://github.com/strongloop/loopback-next.git",
58
- "directory": "packages/rest-explorer"
40
+ "peerDependencies": {
41
+ "@loopback/core": "^2.16.0",
42
+ "@loopback/rest": "^9.3.0"
43
+ },
44
+ "dependencies": {
45
+ "ejs": "^3.1.6",
46
+ "swagger-ui-dist": "3.48.0",
47
+ "tslib": "^2.2.0"
48
+ },
49
+ "devDependencies": {
50
+ "@loopback/build": "^6.4.0",
51
+ "@loopback/core": "^2.16.0",
52
+ "@loopback/eslint-config": "^10.2.0",
53
+ "@loopback/rest": "^9.3.0",
54
+ "@loopback/testlab": "^3.4.0",
55
+ "@types/ejs": "^3.0.6",
56
+ "@types/express": "^4.17.11",
57
+ "@types/node": "^10.17.59",
58
+ "express": "^4.17.1"
59
59
  },
60
- "gitHead": "fd33be0291c4653bee885535d27ebfd8af264e42"
60
+ "gitHead": "2ca802912d8c7750d0256f3c3d493c4525415201"
61
61
  }
@@ -17,10 +17,8 @@ import path from 'path';
17
17
  import {RestExplorerBindings} from './rest-explorer.keys';
18
18
  import {RestExplorerConfig} from './rest-explorer.types';
19
19
 
20
- // TODO(bajtos) Allow users to customize the template
21
- const indexHtml = path.resolve(__dirname, '../templates/index.html.ejs');
22
- const template = fs.readFileSync(indexHtml, 'utf-8');
23
- const templateFn = ejs.compile(template);
20
+ let prevIndexTemplatePath: string;
21
+ let templateFn: ejs.TemplateFunction;
24
22
 
25
23
  export class ExplorerController {
26
24
  static readonly OPENAPI_RELATIVE_URL = 'openapi.json';
@@ -32,6 +30,7 @@ export class ExplorerController {
32
30
  private openApiSpecUrl: string;
33
31
  private useSelfHostedSpec: boolean;
34
32
  private swaggerThemeFile: string;
33
+ private indexTemplatePath: string;
35
34
 
36
35
  constructor(
37
36
  @inject(RestBindings.CONFIG, {optional: true})
@@ -46,6 +45,9 @@ export class ExplorerController {
46
45
  this.openApiSpecUrl = this.getOpenApiSpecUrl(restConfig);
47
46
  this.swaggerThemeFile =
48
47
  explorerConfig.swaggerThemeFile ?? './swagger-ui.css';
48
+ this.indexTemplatePath =
49
+ explorerConfig.indexTemplatePath ??
50
+ path.resolve(__dirname, '../templates/index.html.ejs');
49
51
  }
50
52
 
51
53
  indexRedirect() {
@@ -87,6 +89,12 @@ export class ExplorerController {
87
89
  swaggerThemeFile,
88
90
  };
89
91
 
92
+ if (prevIndexTemplatePath !== this.indexTemplatePath) {
93
+ const template = fs.readFileSync(this.indexTemplatePath, 'utf-8');
94
+ templateFn = ejs.compile(template);
95
+ prevIndexTemplatePath = this.indexTemplatePath;
96
+ }
97
+
90
98
  const homePage = templateFn(data);
91
99
  this.requestContext.response
92
100
  .status(200)
@@ -32,4 +32,9 @@ export type RestExplorerConfig = {
32
32
 
33
33
  // Relative URL of the theme CSS file
34
34
  swaggerThemeFile?: string;
35
+
36
+ /* Absolute path to a .html.ejs template to optionally override
37
+ templates/index.html.ejs
38
+ */
39
+ indexTemplatePath?: string;
35
40
  };