openapi-explorer 0.8.292 → 0.8.293

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-explorer",
3
- "version": "0.8.292",
3
+ "version": "0.8.293",
4
4
  "description": "OpenAPI Explorer - API viewer with dynamically generated components, documentation, and interaction console",
5
5
  "author": "Rhosys Developers <developers@rhosys.ch>",
6
6
  "repository": {
@@ -510,16 +510,15 @@ export default class OpenApiExplorer extends LitElement {
510
510
  this.resolvedSpec = null;
511
511
  this.loading = true;
512
512
  this.loadFailed = false;
513
- const isServerUrl = typeof specUrlOrObject === 'string' && specUrlOrObject.match(/^http/);
514
- if (!this.serverUrl && isServerUrl) {
515
- this.serverUrl = new URL(specUrlOrObject).origin;
516
- }
517
- const spec = await ProcessSpec(isServerUrl, specUrlOrObject, this.serverUrl);
513
+ const spec = await ProcessSpec(specUrlOrObject, this.serverUrl);
518
514
  this.loading = false;
519
515
  if (spec === undefined || spec === null) {
520
516
  console.error('Unable to resolve the API spec. '); // eslint-disable-line no-console
521
517
  return;
522
518
  }
519
+ if (!this.serverUrl) {
520
+ this.serverUrl = spec.servers[0].url;
521
+ }
523
522
  this.afterSpecParsedAndValidated(spec);
524
523
  } catch (err) {
525
524
  this.loading = false;
@@ -3,7 +3,8 @@ import { marked } from 'marked';
3
3
  import yaml from 'js-yaml';
4
4
  import { invalidCharsRegEx } from './common-utils';
5
5
 
6
- export default async function ProcessSpec(requiresLookup, specUrlOrObject, serverUrl = '') {
6
+ export default async function ProcessSpec(specUrlOrObject, serverUrl = '') {
7
+ const inputSpecIsAUrl = typeof specUrlOrObject === 'string' && specUrlOrObject.match(/^http/);
7
8
  let specMeta;
8
9
 
9
10
  // Dynamically resolve non yaml or json files and insert their descriptions where necessary
@@ -14,7 +15,7 @@ export default async function ProcessSpec(requiresLookup, specUrlOrObject, serve
14
15
  return val;
15
16
  }
16
17
 
17
- if (requiresLookup) {
18
+ if (inputSpecIsAUrl) {
18
19
  specMeta = await SwaggerClient({ allowMetaPatches: false, url: specUrlOrObject, responseInterceptor });
19
20
  } else if (typeof specUrlOrObject === 'string') {
20
21
  specMeta = await SwaggerClient({ allowMetaPatches: false, spec: yaml.load(specUrlOrObject), responseInterceptor });
@@ -71,7 +72,7 @@ export default async function ProcessSpec(requiresLookup, specUrlOrObject, serve
71
72
 
72
73
  // Servers
73
74
  let servers = [];
74
- if (jsonParsedSpec.servers && Array.isArray(jsonParsedSpec.servers) && jsonParsedSpec.servers.length) {
75
+ if (Array.isArray(jsonParsedSpec.servers) && jsonParsedSpec.servers.length) {
75
76
  jsonParsedSpec.servers.forEach((v) => {
76
77
  let computedUrl = v.url.trim();
77
78
  if (!(computedUrl.startsWith('http') || computedUrl.startsWith('//') || computedUrl.startsWith('{'))) {
@@ -90,11 +91,13 @@ export default async function ProcessSpec(requiresLookup, specUrlOrObject, serve
90
91
  }
91
92
  v.computedUrl = computedUrl;
92
93
  });
93
- if (serverUrl) {
94
+ if (serverUrl && !jsonParsedSpec.servers.some(s => s.url === serverUrl || s.computedUrl === serverUrl)) {
94
95
  jsonParsedSpec.servers.push({ url: serverUrl, computedUrl: serverUrl });
95
96
  }
96
97
  } else if (serverUrl) {
97
98
  jsonParsedSpec.servers = [{ url: serverUrl, computedUrl: serverUrl }];
99
+ } else if (inputSpecIsAUrl) {
100
+ jsonParsedSpec.servers = [{ url: new URL(specUrlOrObject).origin, computedUrl: new URL(specUrlOrObject).origin }];
98
101
  } else if (window.location.origin.startsWith('http')) {
99
102
  jsonParsedSpec.servers = [{ url: window.location.origin, computedUrl: window.location.origin }];
100
103
  } else {