mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-09 13:36:13 +00:00
Add multiple servers support to JS API client (#1974)
* add multiple servers support to JS ES6 * multiple server support in js es5 * using exports in es5 * fix index check * add oas v3 js es6 client to travis
This commit is contained in:
@@ -162,6 +162,8 @@ Class | Method | HTTP request | Description
|
||||
- [OpenApiPetstore.ReadOnlyFirst](docs/ReadOnlyFirst.md)
|
||||
- [OpenApiPetstore.SpecialModelName](docs/SpecialModelName.md)
|
||||
- [OpenApiPetstore.Tag](docs/Tag.md)
|
||||
- [OpenApiPetstore.TypeHolderDefault](docs/TypeHolderDefault.md)
|
||||
- [OpenApiPetstore.TypeHolderExample](docs/TypeHolderExample.md)
|
||||
- [OpenApiPetstore.User](docs/User.md)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
# OpenApiPetstore.TypeHolderDefault
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**stringItem** | **String** | | [default to 'what']
|
||||
**numberItem** | **Number** | |
|
||||
**integerItem** | **Number** | |
|
||||
**boolItem** | **Boolean** | | [default to true]
|
||||
**arrayItem** | **[Number]** | |
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
# OpenApiPetstore.TypeHolderExample
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**stringItem** | **String** | |
|
||||
**numberItem** | **Number** | |
|
||||
**integerItem** | **Number** | |
|
||||
**boolItem** | **Boolean** | |
|
||||
**arrayItem** | **[Number]** | |
|
||||
|
||||
|
||||
3511
samples/client/petstore/javascript-es6/package-lock.json
generated
Normal file
3511
samples/client/petstore/javascript-es6/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -537,6 +537,46 @@ class ApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of host settings
|
||||
* @returns An array of host settings
|
||||
*/
|
||||
hostSettings() {
|
||||
return [
|
||||
{
|
||||
'url': "http://petstore.swagger.io:80/v2",
|
||||
'description': "No description provided",
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
getBasePathFromSettings(index, variables={}) {
|
||||
var servers = this.hostSettings();
|
||||
|
||||
// check array index out of bound
|
||||
if (index < 0 || index >= servers.length) {
|
||||
throw new Error("Invalid index " + index + " when selecting the host settings. Must be less than " + servers.length);
|
||||
}
|
||||
|
||||
var server = servers[index];
|
||||
var url = server['url'];
|
||||
|
||||
// go through variable and assign a value
|
||||
for (var variable_name in server['variables']) {
|
||||
if (variable_name in variables) {
|
||||
if (server['variables'][variable_name]['enum_values'].includes(variables[variable_name])) {
|
||||
url = url.replace("{" + variable_name + "}", variables[variable_name]);
|
||||
} else {
|
||||
throw new Error("The variable `" + variable_name + "` in the host URL has invalid value " + variables[variable_name] + ". Must be " + server['variables'][variable_name]['enum_values'] + ".");
|
||||
}
|
||||
} else {
|
||||
// use default value
|
||||
url = url.replace("{" + variable_name + "}", server['variables'][variable_name]['default_value'])
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new map or array model from REST data.
|
||||
* @param data {Object|Array} The REST data.
|
||||
|
||||
@@ -46,6 +46,8 @@ import Pet from './model/Pet';
|
||||
import ReadOnlyFirst from './model/ReadOnlyFirst';
|
||||
import SpecialModelName from './model/SpecialModelName';
|
||||
import Tag from './model/Tag';
|
||||
import TypeHolderDefault from './model/TypeHolderDefault';
|
||||
import TypeHolderExample from './model/TypeHolderExample';
|
||||
import User from './model/User';
|
||||
import AnotherFakeApi from './api/AnotherFakeApi';
|
||||
import FakeApi from './api/FakeApi';
|
||||
@@ -291,6 +293,18 @@ export {
|
||||
*/
|
||||
Tag,
|
||||
|
||||
/**
|
||||
* The TypeHolderDefault model constructor.
|
||||
* @property {module:model/TypeHolderDefault}
|
||||
*/
|
||||
TypeHolderDefault,
|
||||
|
||||
/**
|
||||
* The TypeHolderExample model constructor.
|
||||
* @property {module:model/TypeHolderExample}
|
||||
*/
|
||||
TypeHolderExample,
|
||||
|
||||
/**
|
||||
* The User model constructor.
|
||||
* @property {module:model/User}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*
|
||||
*/
|
||||
|
||||
import ApiClient from '../ApiClient';
|
||||
|
||||
/**
|
||||
* The TypeHolderDefault model module.
|
||||
* @module model/TypeHolderDefault
|
||||
* @version 1.0.0
|
||||
*/
|
||||
class TypeHolderDefault {
|
||||
/**
|
||||
* Constructs a new <code>TypeHolderDefault</code>.
|
||||
* @alias module:model/TypeHolderDefault
|
||||
* @param stringItem {String}
|
||||
* @param numberItem {Number}
|
||||
* @param integerItem {Number}
|
||||
* @param boolItem {Boolean}
|
||||
* @param arrayItem {Array.<Number>}
|
||||
*/
|
||||
constructor(stringItem, numberItem, integerItem, boolItem, arrayItem) {
|
||||
|
||||
TypeHolderDefault.initialize(this, stringItem, numberItem, integerItem, boolItem, arrayItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the fields of this object.
|
||||
* This method is used by the constructors of any subclasses, in order to implement multiple inheritance (mix-ins).
|
||||
* Only for internal use.
|
||||
*/
|
||||
static initialize(obj, stringItem, numberItem, integerItem, boolItem, arrayItem) {
|
||||
obj['string_item'] = stringItem;
|
||||
obj['number_item'] = numberItem;
|
||||
obj['integer_item'] = integerItem;
|
||||
obj['bool_item'] = boolItem;
|
||||
obj['array_item'] = arrayItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>TypeHolderDefault</code> from a plain JavaScript object, optionally creating a new instance.
|
||||
* Copies all relevant properties from <code>data</code> to <code>obj</code> if supplied or a new instance if not.
|
||||
* @param {Object} data The plain JavaScript object bearing properties of interest.
|
||||
* @param {module:model/TypeHolderDefault} obj Optional instance to populate.
|
||||
* @return {module:model/TypeHolderDefault} The populated <code>TypeHolderDefault</code> instance.
|
||||
*/
|
||||
static constructFromObject(data, obj) {
|
||||
if (data) {
|
||||
obj = obj || new TypeHolderDefault();
|
||||
|
||||
if (data.hasOwnProperty('string_item')) {
|
||||
obj['string_item'] = ApiClient.convertToType(data['string_item'], 'String');
|
||||
}
|
||||
if (data.hasOwnProperty('number_item')) {
|
||||
obj['number_item'] = ApiClient.convertToType(data['number_item'], 'Number');
|
||||
}
|
||||
if (data.hasOwnProperty('integer_item')) {
|
||||
obj['integer_item'] = ApiClient.convertToType(data['integer_item'], 'Number');
|
||||
}
|
||||
if (data.hasOwnProperty('bool_item')) {
|
||||
obj['bool_item'] = ApiClient.convertToType(data['bool_item'], 'Boolean');
|
||||
}
|
||||
if (data.hasOwnProperty('array_item')) {
|
||||
obj['array_item'] = ApiClient.convertToType(data['array_item'], ['Number']);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @member {String} string_item
|
||||
* @default 'what'
|
||||
*/
|
||||
TypeHolderDefault.prototype['string_item'] = 'what';
|
||||
|
||||
/**
|
||||
* @member {Number} number_item
|
||||
*/
|
||||
TypeHolderDefault.prototype['number_item'] = undefined;
|
||||
|
||||
/**
|
||||
* @member {Number} integer_item
|
||||
*/
|
||||
TypeHolderDefault.prototype['integer_item'] = undefined;
|
||||
|
||||
/**
|
||||
* @member {Boolean} bool_item
|
||||
* @default true
|
||||
*/
|
||||
TypeHolderDefault.prototype['bool_item'] = true;
|
||||
|
||||
/**
|
||||
* @member {Array.<Number>} array_item
|
||||
*/
|
||||
TypeHolderDefault.prototype['array_item'] = undefined;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export default TypeHolderDefault;
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*
|
||||
*/
|
||||
|
||||
import ApiClient from '../ApiClient';
|
||||
|
||||
/**
|
||||
* The TypeHolderExample model module.
|
||||
* @module model/TypeHolderExample
|
||||
* @version 1.0.0
|
||||
*/
|
||||
class TypeHolderExample {
|
||||
/**
|
||||
* Constructs a new <code>TypeHolderExample</code>.
|
||||
* @alias module:model/TypeHolderExample
|
||||
* @param stringItem {String}
|
||||
* @param numberItem {Number}
|
||||
* @param integerItem {Number}
|
||||
* @param boolItem {Boolean}
|
||||
* @param arrayItem {Array.<Number>}
|
||||
*/
|
||||
constructor(stringItem, numberItem, integerItem, boolItem, arrayItem) {
|
||||
|
||||
TypeHolderExample.initialize(this, stringItem, numberItem, integerItem, boolItem, arrayItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the fields of this object.
|
||||
* This method is used by the constructors of any subclasses, in order to implement multiple inheritance (mix-ins).
|
||||
* Only for internal use.
|
||||
*/
|
||||
static initialize(obj, stringItem, numberItem, integerItem, boolItem, arrayItem) {
|
||||
obj['string_item'] = stringItem;
|
||||
obj['number_item'] = numberItem;
|
||||
obj['integer_item'] = integerItem;
|
||||
obj['bool_item'] = boolItem;
|
||||
obj['array_item'] = arrayItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>TypeHolderExample</code> from a plain JavaScript object, optionally creating a new instance.
|
||||
* Copies all relevant properties from <code>data</code> to <code>obj</code> if supplied or a new instance if not.
|
||||
* @param {Object} data The plain JavaScript object bearing properties of interest.
|
||||
* @param {module:model/TypeHolderExample} obj Optional instance to populate.
|
||||
* @return {module:model/TypeHolderExample} The populated <code>TypeHolderExample</code> instance.
|
||||
*/
|
||||
static constructFromObject(data, obj) {
|
||||
if (data) {
|
||||
obj = obj || new TypeHolderExample();
|
||||
|
||||
if (data.hasOwnProperty('string_item')) {
|
||||
obj['string_item'] = ApiClient.convertToType(data['string_item'], 'String');
|
||||
}
|
||||
if (data.hasOwnProperty('number_item')) {
|
||||
obj['number_item'] = ApiClient.convertToType(data['number_item'], 'Number');
|
||||
}
|
||||
if (data.hasOwnProperty('integer_item')) {
|
||||
obj['integer_item'] = ApiClient.convertToType(data['integer_item'], 'Number');
|
||||
}
|
||||
if (data.hasOwnProperty('bool_item')) {
|
||||
obj['bool_item'] = ApiClient.convertToType(data['bool_item'], 'Boolean');
|
||||
}
|
||||
if (data.hasOwnProperty('array_item')) {
|
||||
obj['array_item'] = ApiClient.convertToType(data['array_item'], ['Number']);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @member {String} string_item
|
||||
*/
|
||||
TypeHolderExample.prototype['string_item'] = undefined;
|
||||
|
||||
/**
|
||||
* @member {Number} number_item
|
||||
*/
|
||||
TypeHolderExample.prototype['number_item'] = undefined;
|
||||
|
||||
/**
|
||||
* @member {Number} integer_item
|
||||
*/
|
||||
TypeHolderExample.prototype['integer_item'] = undefined;
|
||||
|
||||
/**
|
||||
* @member {Boolean} bool_item
|
||||
*/
|
||||
TypeHolderExample.prototype['bool_item'] = undefined;
|
||||
|
||||
/**
|
||||
* @member {Array.<Number>} array_item
|
||||
*/
|
||||
TypeHolderExample.prototype['array_item'] = undefined;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export default TypeHolderExample;
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*
|
||||
*/
|
||||
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD.
|
||||
define(['expect.js', '../../src/index'], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
// CommonJS-like environments that support module.exports, like Node.
|
||||
factory(require('expect.js'), require('../../src/index'));
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
factory(root.expect, root.OpenApiPetstore);
|
||||
}
|
||||
}(this, function(expect, OpenApiPetstore) {
|
||||
'use strict';
|
||||
|
||||
var instance;
|
||||
|
||||
beforeEach(function() {
|
||||
instance = new OpenApiPetstore.TypeHolderDefault();
|
||||
});
|
||||
|
||||
var getProperty = function(object, getter, property) {
|
||||
// Use getter method if present; otherwise, get the property directly.
|
||||
if (typeof object[getter] === 'function')
|
||||
return object[getter]();
|
||||
else
|
||||
return object[property];
|
||||
}
|
||||
|
||||
var setProperty = function(object, setter, property, value) {
|
||||
// Use setter method if present; otherwise, set the property directly.
|
||||
if (typeof object[setter] === 'function')
|
||||
object[setter](value);
|
||||
else
|
||||
object[property] = value;
|
||||
}
|
||||
|
||||
describe('TypeHolderDefault', function() {
|
||||
it('should create an instance of TypeHolderDefault', function() {
|
||||
// uncomment below and update the code to test TypeHolderDefault
|
||||
//var instane = new OpenApiPetstore.TypeHolderDefault();
|
||||
//expect(instance).to.be.a(OpenApiPetstore.TypeHolderDefault);
|
||||
});
|
||||
|
||||
it('should have the property stringItem (base name: "string_item")', function() {
|
||||
// uncomment below and update the code to test the property stringItem
|
||||
//var instane = new OpenApiPetstore.TypeHolderDefault();
|
||||
//expect(instance).to.be();
|
||||
});
|
||||
|
||||
it('should have the property numberItem (base name: "number_item")', function() {
|
||||
// uncomment below and update the code to test the property numberItem
|
||||
//var instane = new OpenApiPetstore.TypeHolderDefault();
|
||||
//expect(instance).to.be();
|
||||
});
|
||||
|
||||
it('should have the property integerItem (base name: "integer_item")', function() {
|
||||
// uncomment below and update the code to test the property integerItem
|
||||
//var instane = new OpenApiPetstore.TypeHolderDefault();
|
||||
//expect(instance).to.be();
|
||||
});
|
||||
|
||||
it('should have the property boolItem (base name: "bool_item")', function() {
|
||||
// uncomment below and update the code to test the property boolItem
|
||||
//var instane = new OpenApiPetstore.TypeHolderDefault();
|
||||
//expect(instance).to.be();
|
||||
});
|
||||
|
||||
it('should have the property arrayItem (base name: "array_item")', function() {
|
||||
// uncomment below and update the code to test the property arrayItem
|
||||
//var instane = new OpenApiPetstore.TypeHolderDefault();
|
||||
//expect(instance).to.be();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}));
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*
|
||||
*/
|
||||
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD.
|
||||
define(['expect.js', '../../src/index'], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
// CommonJS-like environments that support module.exports, like Node.
|
||||
factory(require('expect.js'), require('../../src/index'));
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
factory(root.expect, root.OpenApiPetstore);
|
||||
}
|
||||
}(this, function(expect, OpenApiPetstore) {
|
||||
'use strict';
|
||||
|
||||
var instance;
|
||||
|
||||
beforeEach(function() {
|
||||
instance = new OpenApiPetstore.TypeHolderExample();
|
||||
});
|
||||
|
||||
var getProperty = function(object, getter, property) {
|
||||
// Use getter method if present; otherwise, get the property directly.
|
||||
if (typeof object[getter] === 'function')
|
||||
return object[getter]();
|
||||
else
|
||||
return object[property];
|
||||
}
|
||||
|
||||
var setProperty = function(object, setter, property, value) {
|
||||
// Use setter method if present; otherwise, set the property directly.
|
||||
if (typeof object[setter] === 'function')
|
||||
object[setter](value);
|
||||
else
|
||||
object[property] = value;
|
||||
}
|
||||
|
||||
describe('TypeHolderExample', function() {
|
||||
it('should create an instance of TypeHolderExample', function() {
|
||||
// uncomment below and update the code to test TypeHolderExample
|
||||
//var instane = new OpenApiPetstore.TypeHolderExample();
|
||||
//expect(instance).to.be.a(OpenApiPetstore.TypeHolderExample);
|
||||
});
|
||||
|
||||
it('should have the property stringItem (base name: "string_item")', function() {
|
||||
// uncomment below and update the code to test the property stringItem
|
||||
//var instane = new OpenApiPetstore.TypeHolderExample();
|
||||
//expect(instance).to.be();
|
||||
});
|
||||
|
||||
it('should have the property numberItem (base name: "number_item")', function() {
|
||||
// uncomment below and update the code to test the property numberItem
|
||||
//var instane = new OpenApiPetstore.TypeHolderExample();
|
||||
//expect(instance).to.be();
|
||||
});
|
||||
|
||||
it('should have the property integerItem (base name: "integer_item")', function() {
|
||||
// uncomment below and update the code to test the property integerItem
|
||||
//var instane = new OpenApiPetstore.TypeHolderExample();
|
||||
//expect(instance).to.be();
|
||||
});
|
||||
|
||||
it('should have the property boolItem (base name: "bool_item")', function() {
|
||||
// uncomment below and update the code to test the property boolItem
|
||||
//var instane = new OpenApiPetstore.TypeHolderExample();
|
||||
//expect(instance).to.be();
|
||||
});
|
||||
|
||||
it('should have the property arrayItem (base name: "array_item")', function() {
|
||||
// uncomment below and update the code to test the property arrayItem
|
||||
//var instane = new OpenApiPetstore.TypeHolderExample();
|
||||
//expect(instance).to.be();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}));
|
||||
Reference in New Issue
Block a user