swagger-client 3.24.0 → 3.24.1

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.
@@ -3,4 +3,5 @@ export { default as findOperation } from './find-operation.js';
3
3
  export { default as getOperationRaw } from './get-operation-raw.js';
4
4
  export { default as opId } from './op-id.js';
5
5
  export { default as idFromPathMethod } from './id-from-path-method/index.js';
6
- export { default as idFromPathMethodLegacy } from './id-from-path-method/legacy.js';
6
+ export { default as idFromPathMethodLegacy } from './id-from-path-method/legacy.js';
7
+ export { default as isHttpUrl } from './is-http-url.js';
@@ -0,0 +1,5 @@
1
+ import { url } from '@swagger-api/apidom-reference/configuration/empty';
2
+ const {
3
+ isHttpUrl
4
+ } = url;
5
+ export default isHttpUrl;
package/es/index.js CHANGED
@@ -8,7 +8,8 @@ import openApi30ResolveStrategy from './resolver/strategies/openapi-3-0/index.js
8
8
  import openApi31ApiDOMResolveStrategy from './resolver/strategies/openapi-3-1-apidom/index.js';
9
9
  import { makeApisTagOperation } from './interfaces.js';
10
10
  import { execute, buildRequest, baseUrl } from './execute/index.js';
11
- import { opId } from './helpers/index.js';
11
+ import { opId, isHttpUrl } from './helpers/index.js';
12
+ import { isOpenAPI2, isOpenAPI3 } from './helpers/openapi-predicates.js';
12
13
  import HttpResolverSwaggerClient from './resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js';
13
14
  import JsonParser from './resolver/apidom/reference/parse/parsers/json/index.js';
14
15
  import YamlParser from './resolver/apidom/reference/parse/parsers/yaml-1-2/index.js';
@@ -123,8 +124,7 @@ Swagger.prototype.applyDefaults = function applyDefaults() {
123
124
  spec
124
125
  } = this;
125
126
  const specUrl = this.url;
126
- // TODO: OAS3: support servers here
127
- if (specUrl && specUrl.startsWith('http')) {
127
+ if (isOpenAPI2(spec) && isHttpUrl(specUrl)) {
128
128
  const parsed = new URL(specUrl);
129
129
  if (!spec.host) {
130
130
  spec.host = parsed.host;
@@ -135,6 +135,12 @@ Swagger.prototype.applyDefaults = function applyDefaults() {
135
135
  if (!spec.basePath) {
136
136
  spec.basePath = '/';
137
137
  }
138
+ } else if (isOpenAPI3(spec) && isHttpUrl(specUrl)) {
139
+ if (!spec.servers) {
140
+ spec.servers = [{
141
+ url: specUrl
142
+ }];
143
+ }
138
144
  }
139
145
  };
140
146
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
4
  exports.__esModule = true;
5
- exports.opId = exports.idFromPathMethodLegacy = exports.idFromPathMethod = exports.getOperationRaw = exports.findOperation = exports.eachOperation = void 0;
5
+ exports.opId = exports.isHttpUrl = exports.idFromPathMethodLegacy = exports.idFromPathMethod = exports.getOperationRaw = exports.findOperation = exports.eachOperation = void 0;
6
6
  var _eachOperation = _interopRequireDefault(require("./each-operation.js"));
7
7
  exports.eachOperation = _eachOperation.default;
8
8
  var _findOperation = _interopRequireDefault(require("./find-operation.js"));
@@ -14,4 +14,6 @@ exports.opId = _opId.default;
14
14
  var _index = _interopRequireDefault(require("./id-from-path-method/index.js"));
15
15
  exports.idFromPathMethod = _index.default;
16
16
  var _legacy = _interopRequireDefault(require("./id-from-path-method/legacy.js"));
17
- exports.idFromPathMethodLegacy = _legacy.default;
17
+ exports.idFromPathMethodLegacy = _legacy.default;
18
+ var _isHttpUrl = _interopRequireDefault(require("./is-http-url.js"));
19
+ exports.isHttpUrl = _isHttpUrl.default;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ var _empty = require("@swagger-api/apidom-reference/configuration/empty");
6
+ const {
7
+ isHttpUrl
8
+ } = _empty.url;
9
+ var _default = exports.default = isHttpUrl;
package/lib/index.js CHANGED
@@ -14,6 +14,7 @@ var _index7 = _interopRequireDefault(require("./resolver/strategies/openapi-3-1-
14
14
  var _interfaces = require("./interfaces.js");
15
15
  var _index8 = require("./execute/index.js");
16
16
  var _index9 = require("./helpers/index.js");
17
+ var _openapiPredicates = require("./helpers/openapi-predicates.js");
17
18
  var _index10 = _interopRequireDefault(require("./resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js"));
18
19
  var _index11 = _interopRequireDefault(require("./resolver/apidom/reference/parse/parsers/json/index.js"));
19
20
  var _index12 = _interopRequireDefault(require("./resolver/apidom/reference/parse/parsers/yaml-1-2/index.js"));
@@ -134,8 +135,7 @@ Swagger.prototype.applyDefaults = function applyDefaults() {
134
135
  spec
135
136
  } = this;
136
137
  const specUrl = this.url;
137
- // TODO: OAS3: support servers here
138
- if (specUrl && specUrl.startsWith('http')) {
138
+ if ((0, _openapiPredicates.isOpenAPI2)(spec) && (0, _index9.isHttpUrl)(specUrl)) {
139
139
  const parsed = new URL(specUrl);
140
140
  if (!spec.host) {
141
141
  spec.host = parsed.host;
@@ -146,6 +146,12 @@ Swagger.prototype.applyDefaults = function applyDefaults() {
146
146
  if (!spec.basePath) {
147
147
  spec.basePath = '/';
148
148
  }
149
+ } else if ((0, _openapiPredicates.isOpenAPI3)(spec) && (0, _index9.isHttpUrl)(specUrl)) {
150
+ if (!spec.servers) {
151
+ spec.servers = [{
152
+ url: specUrl
153
+ }];
154
+ }
149
155
  }
150
156
  };
151
157
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swagger-client",
3
- "version": "3.24.0",
3
+ "version": "3.24.1",
4
4
  "description": "SwaggerJS - a collection of interfaces for OAI specs",
5
5
  "browser": {
6
6
  "./src/helpers/btoa.node.js": "./src/helpers/btoa.browser.js",