diff --git a/modules/openapi-generator/src/main/resources/Javascript/partial_model_oneof.mustache b/modules/openapi-generator/src/main/resources/Javascript/partial_model_oneof.mustache
index a0ff043a1d8..bc3d1a31eab 100644
--- a/modules/openapi-generator/src/main/resources/Javascript/partial_model_oneof.mustache
+++ b/modules/openapi-generator/src/main/resources/Javascript/partial_model_oneof.mustache
@@ -111,59 +111,67 @@ class {{classname}} {
}
{{/items.isString}}
{{#items.isNumber}}
- // validate array of string
+ // validate array of number
for (const item of instance) {
if (!(typeof instance === 'number' && instance % 1 != 0)) {
throw new Error("Invalid array items. Must be number. Input: " + JSON.stringify(instance));
}
}
{{/items.isNumber}}
+ {{#items.isBoolean}}
+ // validate array of boolean
+ for (const item of instance) {
+ if (!(typeof instance === 'boolean')) {
+ throw new Error("Invalid array items. Must be boolean. Input: " + JSON.stringify(instance));
+ }
+ }
+ {{/items.isBoolean}}
{{/isArray}}
{{^isArray}}
{{#isInteger}}
- // validate array of integer
+ // validate integer
if (!(typeof instance === 'number' && instance % 1 === 0)) {
- throw new Error("Invalid array items. Must be integer. Input: " + JSON.stringify(instance));
+ throw new Error("Invalid value. Must be integer. Input: " + JSON.stringify(instance));
}
{{#maximum}}
{{#minimum}}
if (instance > {{maximum}} || instance < {{minimum}}) {
- throw new Error("Invalid integer value in an array items. Max.: {{maximum}}. Min.: {{minimum}}. Input: " + JSON.stringify(instance));
+ throw new Error("Invalid integer value. Max.: {{maximum}}. Min.: {{minimum}}. Input: " + JSON.stringify(instance));
}
{{/minimum}}
{{^minimum}}
if (instance > {{maximum}}) {
- throw new Error("Invalid integer value in an array items. Max.: {{maximum}}. Input: " + JSON.stringify(instance));
+ throw new Error("Invalid integer value. Max.: {{maximum}}. Input: " + JSON.stringify(instance));
}
{{/minimum}}
{{/maximum}}
{{^maximum}}
{{#minimum}}
if (instance < {{minimum}}) {
- throw new Error("Invalid integer value in an array items. Min.: {{minimum}}. Input: " + JSON.stringify(instance));
+ throw new Error("Invalid integer value. Min.: {{minimum}}. Input: " + JSON.stringify(instance));
}
{{/minimum}}
{{/maximum}}
{{/isInteger}}
{{#isString}}
- // validate array of string
+ // validate string
if (!(typeof instance === 'string')) {
- throw new Error("Invalid input. Must be string. Input: " + JSON.stringify(instance));
+ throw new Error("Invalid value. Must be string. Input: " + JSON.stringify(instance));
}
{{#pattern}}
if (!{{{pattern}}}.test(instance)) {
- throw new Error("Invalid string value in an array items. Must conform to {{{.}}}. Input: " + JSON.stringify(instance));
+ throw new Error("Invalid string value. Must conform to {{{.}}}. Input: " + JSON.stringify(instance));
}
{{/pattern}}
{{#minLength}}
{{#maxLength}}
if (instance.length > {{maxLength}} && instance.length < {{minLength}}) {
- throw new Error("Invalid string value in an array items. Max. length: {{{maxLength}}}. Min. length: {{{minLength}}}. Input: " + JSON.stringify(instance));
+ throw new Error("Invalid string value. Max. length: {{{maxLength}}}. Min. length: {{{minLength}}}. Input: " + JSON.stringify(instance));
}
{{/maxLength}}
{{^maxLength}}
if (instance.length < {{minLength}}) {
- throw new Error("Invalid string value in an array items. Min. length: {{{minLength}}}. Input: " + instance);
+ throw new Error("Invalid string value. Min. length: {{{minLength}}}. Input: " + instance);
}
{{/maxLength}}
{{/minLength}}
@@ -176,11 +184,17 @@ class {{classname}} {
{{/minLength}}
{{/isString}}
{{#isNumber}}
- // validate array of string
+ // validate number
if (!(typeof instance === 'number' && instance % 1 != 0)) {
- throw new Error("Invalid array items. Must be number. Input: " + JSON.stringify(instance));
+ throw new Error("Invalid value. Must be number. Input: " + JSON.stringify(instance));
}
{{/isNumber}}
+ {{#isBoolean}}
+ // validate boolean
+ if (!(typeof instance === 'boolean')) {
+ throw new Error("Invalid value. Must be boolean. Input: " + JSON.stringify(instance));
+ }
+ {{/isBoolean}}
{{/isArray}}
this.actualInstance = instance;
{{/isPrimitiveType}}
diff --git a/modules/openapi-generator/src/test/resources/3_0/javascript/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/javascript/petstore-with-fake-endpoints-models-for-testing.yaml
index cac52823a43..602ba230ba5 100644
--- a/modules/openapi-generator/src/test/resources/3_0/javascript/petstore-with-fake-endpoints-models-for-testing.yaml
+++ b/modules/openapi-generator/src/test/resources/3_0/javascript/petstore-with-fake-endpoints-models-for-testing.yaml
@@ -1977,3 +1977,8 @@ components:
- $ref: '#/components/schemas/RgbColor'
- $ref: '#/components/schemas/RgbaColor'
- $ref: '#/components/schemas/HexColor'
+ StringOrBoolean:
+ description: String or boolean
+ oneOf:
+ - type: string
+ - type: boolean
diff --git a/samples/client/petstore/javascript-apollo/.openapi-generator/FILES b/samples/client/petstore/javascript-apollo/.openapi-generator/FILES
index f83260318a5..7582f4f63b7 100644
--- a/samples/client/petstore/javascript-apollo/.openapi-generator/FILES
+++ b/samples/client/petstore/javascript-apollo/.openapi-generator/FILES
@@ -58,6 +58,7 @@ docs/ReadOnlyFirst.md
docs/Return.md
docs/SpecialModelName.md
docs/StoreApi.md
+docs/StringOrBoolean.md
docs/Tag.md
docs/User.md
docs/UserApi.md
@@ -123,5 +124,6 @@ src/model/Pig.js
src/model/ReadOnlyFirst.js
src/model/Return.js
src/model/SpecialModelName.js
+src/model/StringOrBoolean.js
src/model/Tag.js
src/model/User.js
diff --git a/samples/client/petstore/javascript-apollo/README.md b/samples/client/petstore/javascript-apollo/README.md
index a6a90be126d..00a573ce112 100644
--- a/samples/client/petstore/javascript-apollo/README.md
+++ b/samples/client/petstore/javascript-apollo/README.md
@@ -215,6 +215,7 @@ Class | Method | HTTP request | Description
- [OpenApiPetstore.ReadOnlyFirst](docs/ReadOnlyFirst.md)
- [OpenApiPetstore.Return](docs/Return.md)
- [OpenApiPetstore.SpecialModelName](docs/SpecialModelName.md)
+ - [OpenApiPetstore.StringOrBoolean](docs/StringOrBoolean.md)
- [OpenApiPetstore.Tag](docs/Tag.md)
- [OpenApiPetstore.User](docs/User.md)
diff --git a/samples/client/petstore/javascript-apollo/docs/StringOrBoolean.md b/samples/client/petstore/javascript-apollo/docs/StringOrBoolean.md
new file mode 100644
index 00000000000..2fd4043fc87
--- /dev/null
+++ b/samples/client/petstore/javascript-apollo/docs/StringOrBoolean.md
@@ -0,0 +1,8 @@
+# OpenApiPetstore.StringOrBoolean
+
+## Properties
+
+Name | Type | Description | Notes
+------------ | ------------- | ------------- | -------------
+
+
diff --git a/samples/client/petstore/javascript-apollo/src/index.js b/samples/client/petstore/javascript-apollo/src/index.js
index a95a17ec1b0..f890e139a5e 100644
--- a/samples/client/petstore/javascript-apollo/src/index.js
+++ b/samples/client/petstore/javascript-apollo/src/index.js
@@ -63,6 +63,7 @@ import Pig from './model/Pig';
import ReadOnlyFirst from './model/ReadOnlyFirst';
import Return from './model/Return';
import SpecialModelName from './model/SpecialModelName';
+import StringOrBoolean from './model/StringOrBoolean';
import Tag from './model/Tag';
import User from './model/User';
import AnotherFakeApi from './api/AnotherFakeApi';
@@ -412,6 +413,12 @@ export {
*/
SpecialModelName,
+ /**
+ * The StringOrBoolean model constructor.
+ * @property {module:model/StringOrBoolean}
+ */
+ StringOrBoolean,
+
/**
* The Tag model constructor.
* @property {module:model/Tag}
diff --git a/samples/client/petstore/javascript-apollo/src/model/Color.js b/samples/client/petstore/javascript-apollo/src/model/Color.js
index cdeb9bf6158..70daad82ce6 100644
--- a/samples/client/petstore/javascript-apollo/src/model/Color.js
+++ b/samples/client/petstore/javascript-apollo/src/model/Color.js
@@ -84,15 +84,15 @@ class Color {
// Hex color string, such as #00FF00.
try {
- // validate array of string
+ // validate string
if (!(typeof instance === 'string')) {
- throw new Error("Invalid input. Must be string. Input: " + JSON.stringify(instance));
+ throw new Error("Invalid value. Must be string. Input: " + JSON.stringify(instance));
}
if (!/^#(?:[0-9a-fA-F]{3}){1,2}$/.test(instance)) {
- throw new Error("Invalid string value in an array items. Must conform to /^#(?:[0-9a-fA-F]{3}){1,2}$/. Input: " + JSON.stringify(instance));
+ throw new Error("Invalid string value. Must conform to /^#(?:[0-9a-fA-F]{3}){1,2}$/. Input: " + JSON.stringify(instance));
}
if (instance.length > 7 && instance.length < 7) {
- throw new Error("Invalid string value in an array items. Max. length: 7. Min. length: 7. Input: " + JSON.stringify(instance));
+ throw new Error("Invalid string value. Max. length: 7. Min. length: 7. Input: " + JSON.stringify(instance));
}
this.actualInstance = instance;
match++;
diff --git a/samples/client/petstore/javascript-apollo/src/model/StringOrBoolean.js b/samples/client/petstore/javascript-apollo/src/model/StringOrBoolean.js
new file mode 100644
index 00000000000..029e14e41a7
--- /dev/null
+++ b/samples/client/petstore/javascript-apollo/src/model/StringOrBoolean.js
@@ -0,0 +1,119 @@
+/**
+ * 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: \" \\
+ *
+ * The version of the OpenAPI document: 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 StringOrBoolean model module.
+ * @module model/StringOrBoolean
+ * @version 1.0.0
+ */
+class StringOrBoolean {
+ /**
+ * Constructs a new StringOrBoolean
.
+ * String or boolean
+ * @alias module:model/StringOrBoolean
+ * @param {(module:model/Boolean|module:model/String)} instance The actual instance to initialize StringOrBoolean.
+ */
+ constructor(instance = null) {
+ if (instance === null) {
+ this.actualInstance = null;
+ return;
+ }
+ var match = 0;
+ var errorMessages = [];
+ try {
+ // validate string
+ if (!(typeof instance === 'string')) {
+ throw new Error("Invalid value. Must be string. Input: " + JSON.stringify(instance));
+ }
+ this.actualInstance = instance;
+ match++;
+ } catch(err) {
+ // json data failed to deserialize into String
+ errorMessages.push("Failed to construct String: " + err)
+ }
+
+ try {
+ // validate boolean
+ if (!(typeof instance === 'boolean')) {
+ throw new Error("Invalid value. Must be boolean. Input: " + JSON.stringify(instance));
+ }
+ this.actualInstance = instance;
+ match++;
+ } catch(err) {
+ // json data failed to deserialize into Boolean
+ errorMessages.push("Failed to construct Boolean: " + err)
+ }
+
+ if (match > 1) {
+ throw new Error("Multiple matches found constructing `StringOrBoolean` with oneOf schemas Boolean, String. Input: " + JSON.stringify(instance));
+ } else if (match === 0) {
+ this.actualInstance = null; // clear the actual instance in case there are multiple matches
+ throw new Error("No match found constructing `StringOrBoolean` with oneOf schemas Boolean, String. Details: " +
+ errorMessages.join(", "));
+ } else { // only 1 match
+ // the input is valid
+ }
+ }
+
+ /**
+ * Constructs a StringOrBoolean
from a plain JavaScript object, optionally creating a new instance.
+ * Copies all relevant properties from data
to obj
if supplied or a new instance if not.
+ * @param {Object} data The plain JavaScript object bearing properties of interest.
+ * @param {module:model/StringOrBoolean} obj Optional instance to populate.
+ * @return {module:model/StringOrBoolean} The populated StringOrBoolean
instance.
+ */
+ static constructFromObject(data, obj) {
+ return new StringOrBoolean(data);
+ }
+
+ /**
+ * Gets the actual instance, which can be Boolean
, String
.
+ * @return {(module:model/Boolean|module:model/String)} The actual instance.
+ */
+ getActualInstance() {
+ return this.actualInstance;
+ }
+
+ /**
+ * Sets the actual instance, which can be Boolean
, String
.
+ * @param {(module:model/Boolean|module:model/String)} obj The actual instance.
+ */
+ setActualInstance(obj) {
+ this.actualInstance = StringOrBoolean.constructFromObject(obj).getActualInstance();
+ }
+
+ /**
+ * Returns the JSON representation of the actual instance.
+ * @return {string}
+ */
+ toJSON = function(){
+ return this.getActualInstance();
+ }
+
+ /**
+ * Create an instance of StringOrBoolean from a JSON string.
+ * @param {string} json_string JSON string.
+ * @return {module:model/StringOrBoolean} An instance of StringOrBoolean.
+ */
+ static fromJSON = function(json_string){
+ return StringOrBoolean.constructFromObject(JSON.parse(json_string));
+ }
+}
+
+
+StringOrBoolean.OneOf = ["Boolean", "String"];
+
+export default StringOrBoolean;
+
diff --git a/samples/client/petstore/javascript-apollo/test/model/StringOrBoolean.spec.js b/samples/client/petstore/javascript-apollo/test/model/StringOrBoolean.spec.js
new file mode 100644
index 00000000000..d6c9a43bbba
--- /dev/null
+++ b/samples/client/petstore/javascript-apollo/test/model/StringOrBoolean.spec.js
@@ -0,0 +1,59 @@
+/**
+ * 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: \" \\
+ *
+ * The version of the OpenAPI document: 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', process.cwd()+'/src/index'], factory);
+ } else if (typeof module === 'object' && module.exports) {
+ // CommonJS-like environments that support module.exports, like Node.
+ factory(require('expect.js'), require(process.cwd()+'/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.StringOrBoolean();
+ });
+
+ 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('StringOrBoolean', function() {
+ it('should create an instance of StringOrBoolean', function() {
+ // uncomment below and update the code to test StringOrBoolean
+ //var instance = new OpenApiPetstore.StringOrBoolean();
+ //expect(instance).to.be.a(OpenApiPetstore.StringOrBoolean);
+ });
+
+ });
+
+}));
diff --git a/samples/client/petstore/javascript-es6/.openapi-generator/FILES b/samples/client/petstore/javascript-es6/.openapi-generator/FILES
index f83260318a5..7582f4f63b7 100644
--- a/samples/client/petstore/javascript-es6/.openapi-generator/FILES
+++ b/samples/client/petstore/javascript-es6/.openapi-generator/FILES
@@ -58,6 +58,7 @@ docs/ReadOnlyFirst.md
docs/Return.md
docs/SpecialModelName.md
docs/StoreApi.md
+docs/StringOrBoolean.md
docs/Tag.md
docs/User.md
docs/UserApi.md
@@ -123,5 +124,6 @@ src/model/Pig.js
src/model/ReadOnlyFirst.js
src/model/Return.js
src/model/SpecialModelName.js
+src/model/StringOrBoolean.js
src/model/Tag.js
src/model/User.js
diff --git a/samples/client/petstore/javascript-es6/README.md b/samples/client/petstore/javascript-es6/README.md
index a6a90be126d..00a573ce112 100644
--- a/samples/client/petstore/javascript-es6/README.md
+++ b/samples/client/petstore/javascript-es6/README.md
@@ -215,6 +215,7 @@ Class | Method | HTTP request | Description
- [OpenApiPetstore.ReadOnlyFirst](docs/ReadOnlyFirst.md)
- [OpenApiPetstore.Return](docs/Return.md)
- [OpenApiPetstore.SpecialModelName](docs/SpecialModelName.md)
+ - [OpenApiPetstore.StringOrBoolean](docs/StringOrBoolean.md)
- [OpenApiPetstore.Tag](docs/Tag.md)
- [OpenApiPetstore.User](docs/User.md)
diff --git a/samples/client/petstore/javascript-es6/docs/StringOrBoolean.md b/samples/client/petstore/javascript-es6/docs/StringOrBoolean.md
new file mode 100644
index 00000000000..2fd4043fc87
--- /dev/null
+++ b/samples/client/petstore/javascript-es6/docs/StringOrBoolean.md
@@ -0,0 +1,8 @@
+# OpenApiPetstore.StringOrBoolean
+
+## Properties
+
+Name | Type | Description | Notes
+------------ | ------------- | ------------- | -------------
+
+
diff --git a/samples/client/petstore/javascript-es6/src/index.js b/samples/client/petstore/javascript-es6/src/index.js
index a95a17ec1b0..f890e139a5e 100644
--- a/samples/client/petstore/javascript-es6/src/index.js
+++ b/samples/client/petstore/javascript-es6/src/index.js
@@ -63,6 +63,7 @@ import Pig from './model/Pig';
import ReadOnlyFirst from './model/ReadOnlyFirst';
import Return from './model/Return';
import SpecialModelName from './model/SpecialModelName';
+import StringOrBoolean from './model/StringOrBoolean';
import Tag from './model/Tag';
import User from './model/User';
import AnotherFakeApi from './api/AnotherFakeApi';
@@ -412,6 +413,12 @@ export {
*/
SpecialModelName,
+ /**
+ * The StringOrBoolean model constructor.
+ * @property {module:model/StringOrBoolean}
+ */
+ StringOrBoolean,
+
/**
* The Tag model constructor.
* @property {module:model/Tag}
diff --git a/samples/client/petstore/javascript-es6/src/model/Color.js b/samples/client/petstore/javascript-es6/src/model/Color.js
index cdeb9bf6158..70daad82ce6 100644
--- a/samples/client/petstore/javascript-es6/src/model/Color.js
+++ b/samples/client/petstore/javascript-es6/src/model/Color.js
@@ -84,15 +84,15 @@ class Color {
// Hex color string, such as #00FF00.
try {
- // validate array of string
+ // validate string
if (!(typeof instance === 'string')) {
- throw new Error("Invalid input. Must be string. Input: " + JSON.stringify(instance));
+ throw new Error("Invalid value. Must be string. Input: " + JSON.stringify(instance));
}
if (!/^#(?:[0-9a-fA-F]{3}){1,2}$/.test(instance)) {
- throw new Error("Invalid string value in an array items. Must conform to /^#(?:[0-9a-fA-F]{3}){1,2}$/. Input: " + JSON.stringify(instance));
+ throw new Error("Invalid string value. Must conform to /^#(?:[0-9a-fA-F]{3}){1,2}$/. Input: " + JSON.stringify(instance));
}
if (instance.length > 7 && instance.length < 7) {
- throw new Error("Invalid string value in an array items. Max. length: 7. Min. length: 7. Input: " + JSON.stringify(instance));
+ throw new Error("Invalid string value. Max. length: 7. Min. length: 7. Input: " + JSON.stringify(instance));
}
this.actualInstance = instance;
match++;
diff --git a/samples/client/petstore/javascript-es6/src/model/StringOrBoolean.js b/samples/client/petstore/javascript-es6/src/model/StringOrBoolean.js
new file mode 100644
index 00000000000..029e14e41a7
--- /dev/null
+++ b/samples/client/petstore/javascript-es6/src/model/StringOrBoolean.js
@@ -0,0 +1,119 @@
+/**
+ * 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: \" \\
+ *
+ * The version of the OpenAPI document: 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 StringOrBoolean model module.
+ * @module model/StringOrBoolean
+ * @version 1.0.0
+ */
+class StringOrBoolean {
+ /**
+ * Constructs a new StringOrBoolean
.
+ * String or boolean
+ * @alias module:model/StringOrBoolean
+ * @param {(module:model/Boolean|module:model/String)} instance The actual instance to initialize StringOrBoolean.
+ */
+ constructor(instance = null) {
+ if (instance === null) {
+ this.actualInstance = null;
+ return;
+ }
+ var match = 0;
+ var errorMessages = [];
+ try {
+ // validate string
+ if (!(typeof instance === 'string')) {
+ throw new Error("Invalid value. Must be string. Input: " + JSON.stringify(instance));
+ }
+ this.actualInstance = instance;
+ match++;
+ } catch(err) {
+ // json data failed to deserialize into String
+ errorMessages.push("Failed to construct String: " + err)
+ }
+
+ try {
+ // validate boolean
+ if (!(typeof instance === 'boolean')) {
+ throw new Error("Invalid value. Must be boolean. Input: " + JSON.stringify(instance));
+ }
+ this.actualInstance = instance;
+ match++;
+ } catch(err) {
+ // json data failed to deserialize into Boolean
+ errorMessages.push("Failed to construct Boolean: " + err)
+ }
+
+ if (match > 1) {
+ throw new Error("Multiple matches found constructing `StringOrBoolean` with oneOf schemas Boolean, String. Input: " + JSON.stringify(instance));
+ } else if (match === 0) {
+ this.actualInstance = null; // clear the actual instance in case there are multiple matches
+ throw new Error("No match found constructing `StringOrBoolean` with oneOf schemas Boolean, String. Details: " +
+ errorMessages.join(", "));
+ } else { // only 1 match
+ // the input is valid
+ }
+ }
+
+ /**
+ * Constructs a StringOrBoolean
from a plain JavaScript object, optionally creating a new instance.
+ * Copies all relevant properties from data
to obj
if supplied or a new instance if not.
+ * @param {Object} data The plain JavaScript object bearing properties of interest.
+ * @param {module:model/StringOrBoolean} obj Optional instance to populate.
+ * @return {module:model/StringOrBoolean} The populated StringOrBoolean
instance.
+ */
+ static constructFromObject(data, obj) {
+ return new StringOrBoolean(data);
+ }
+
+ /**
+ * Gets the actual instance, which can be Boolean
, String
.
+ * @return {(module:model/Boolean|module:model/String)} The actual instance.
+ */
+ getActualInstance() {
+ return this.actualInstance;
+ }
+
+ /**
+ * Sets the actual instance, which can be Boolean
, String
.
+ * @param {(module:model/Boolean|module:model/String)} obj The actual instance.
+ */
+ setActualInstance(obj) {
+ this.actualInstance = StringOrBoolean.constructFromObject(obj).getActualInstance();
+ }
+
+ /**
+ * Returns the JSON representation of the actual instance.
+ * @return {string}
+ */
+ toJSON = function(){
+ return this.getActualInstance();
+ }
+
+ /**
+ * Create an instance of StringOrBoolean from a JSON string.
+ * @param {string} json_string JSON string.
+ * @return {module:model/StringOrBoolean} An instance of StringOrBoolean.
+ */
+ static fromJSON = function(json_string){
+ return StringOrBoolean.constructFromObject(JSON.parse(json_string));
+ }
+}
+
+
+StringOrBoolean.OneOf = ["Boolean", "String"];
+
+export default StringOrBoolean;
+
diff --git a/samples/client/petstore/javascript-es6/test/PetstoreTest.js b/samples/client/petstore/javascript-es6/test/PetstoreTest.js
index dfa424b5aec..dbd2685685b 100644
--- a/samples/client/petstore/javascript-es6/test/PetstoreTest.js
+++ b/samples/client/petstore/javascript-es6/test/PetstoreTest.js
@@ -280,6 +280,20 @@ describe('Petstore', function() {
expect(JSON.stringify(result)).to.be(nested_one_of_json);
});
+ it('should serialize and deserialize StringOrBoolean correctly', function() {
+ // string
+ var json = '"Hello World"'
+ var result = OpenAPIPetstore.ApiClient.convertToType(JSON.parse(json), OpenAPIPetstore.StringOrBoolean);
+ expect(result).to.be.a(OpenAPIPetstore.StringOrBoolean);
+ expect(JSON.stringify(result)).to.be(json);
+
+ // boolean
+ json = 'true'
+ result = OpenAPIPetstore.ApiClient.convertToType(JSON.parse(json), OpenAPIPetstore.StringOrBoolean);
+ expect(result).to.be.a(OpenAPIPetstore.StringOrBoolean);
+ expect(JSON.stringify(result)).to.be(json);
+ });
+
});
});
diff --git a/samples/client/petstore/javascript-es6/test/model/StringOrBoolean.spec.js b/samples/client/petstore/javascript-es6/test/model/StringOrBoolean.spec.js
new file mode 100644
index 00000000000..d6c9a43bbba
--- /dev/null
+++ b/samples/client/petstore/javascript-es6/test/model/StringOrBoolean.spec.js
@@ -0,0 +1,59 @@
+/**
+ * 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: \" \\
+ *
+ * The version of the OpenAPI document: 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', process.cwd()+'/src/index'], factory);
+ } else if (typeof module === 'object' && module.exports) {
+ // CommonJS-like environments that support module.exports, like Node.
+ factory(require('expect.js'), require(process.cwd()+'/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.StringOrBoolean();
+ });
+
+ 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('StringOrBoolean', function() {
+ it('should create an instance of StringOrBoolean', function() {
+ // uncomment below and update the code to test StringOrBoolean
+ //var instance = new OpenApiPetstore.StringOrBoolean();
+ //expect(instance).to.be.a(OpenApiPetstore.StringOrBoolean);
+ });
+
+ });
+
+}));
diff --git a/samples/client/petstore/javascript-promise-es6/.openapi-generator/FILES b/samples/client/petstore/javascript-promise-es6/.openapi-generator/FILES
index f83260318a5..7582f4f63b7 100644
--- a/samples/client/petstore/javascript-promise-es6/.openapi-generator/FILES
+++ b/samples/client/petstore/javascript-promise-es6/.openapi-generator/FILES
@@ -58,6 +58,7 @@ docs/ReadOnlyFirst.md
docs/Return.md
docs/SpecialModelName.md
docs/StoreApi.md
+docs/StringOrBoolean.md
docs/Tag.md
docs/User.md
docs/UserApi.md
@@ -123,5 +124,6 @@ src/model/Pig.js
src/model/ReadOnlyFirst.js
src/model/Return.js
src/model/SpecialModelName.js
+src/model/StringOrBoolean.js
src/model/Tag.js
src/model/User.js
diff --git a/samples/client/petstore/javascript-promise-es6/README.md b/samples/client/petstore/javascript-promise-es6/README.md
index 47a8d3c3453..3d310993bda 100644
--- a/samples/client/petstore/javascript-promise-es6/README.md
+++ b/samples/client/petstore/javascript-promise-es6/README.md
@@ -213,6 +213,7 @@ Class | Method | HTTP request | Description
- [OpenApiPetstore.ReadOnlyFirst](docs/ReadOnlyFirst.md)
- [OpenApiPetstore.Return](docs/Return.md)
- [OpenApiPetstore.SpecialModelName](docs/SpecialModelName.md)
+ - [OpenApiPetstore.StringOrBoolean](docs/StringOrBoolean.md)
- [OpenApiPetstore.Tag](docs/Tag.md)
- [OpenApiPetstore.User](docs/User.md)
diff --git a/samples/client/petstore/javascript-promise-es6/docs/StringOrBoolean.md b/samples/client/petstore/javascript-promise-es6/docs/StringOrBoolean.md
new file mode 100644
index 00000000000..2fd4043fc87
--- /dev/null
+++ b/samples/client/petstore/javascript-promise-es6/docs/StringOrBoolean.md
@@ -0,0 +1,8 @@
+# OpenApiPetstore.StringOrBoolean
+
+## Properties
+
+Name | Type | Description | Notes
+------------ | ------------- | ------------- | -------------
+
+
diff --git a/samples/client/petstore/javascript-promise-es6/src/index.js b/samples/client/petstore/javascript-promise-es6/src/index.js
index a95a17ec1b0..f890e139a5e 100644
--- a/samples/client/petstore/javascript-promise-es6/src/index.js
+++ b/samples/client/petstore/javascript-promise-es6/src/index.js
@@ -63,6 +63,7 @@ import Pig from './model/Pig';
import ReadOnlyFirst from './model/ReadOnlyFirst';
import Return from './model/Return';
import SpecialModelName from './model/SpecialModelName';
+import StringOrBoolean from './model/StringOrBoolean';
import Tag from './model/Tag';
import User from './model/User';
import AnotherFakeApi from './api/AnotherFakeApi';
@@ -412,6 +413,12 @@ export {
*/
SpecialModelName,
+ /**
+ * The StringOrBoolean model constructor.
+ * @property {module:model/StringOrBoolean}
+ */
+ StringOrBoolean,
+
/**
* The Tag model constructor.
* @property {module:model/Tag}
diff --git a/samples/client/petstore/javascript-promise-es6/src/model/Color.js b/samples/client/petstore/javascript-promise-es6/src/model/Color.js
index cdeb9bf6158..70daad82ce6 100644
--- a/samples/client/petstore/javascript-promise-es6/src/model/Color.js
+++ b/samples/client/petstore/javascript-promise-es6/src/model/Color.js
@@ -84,15 +84,15 @@ class Color {
// Hex color string, such as #00FF00.
try {
- // validate array of string
+ // validate string
if (!(typeof instance === 'string')) {
- throw new Error("Invalid input. Must be string. Input: " + JSON.stringify(instance));
+ throw new Error("Invalid value. Must be string. Input: " + JSON.stringify(instance));
}
if (!/^#(?:[0-9a-fA-F]{3}){1,2}$/.test(instance)) {
- throw new Error("Invalid string value in an array items. Must conform to /^#(?:[0-9a-fA-F]{3}){1,2}$/. Input: " + JSON.stringify(instance));
+ throw new Error("Invalid string value. Must conform to /^#(?:[0-9a-fA-F]{3}){1,2}$/. Input: " + JSON.stringify(instance));
}
if (instance.length > 7 && instance.length < 7) {
- throw new Error("Invalid string value in an array items. Max. length: 7. Min. length: 7. Input: " + JSON.stringify(instance));
+ throw new Error("Invalid string value. Max. length: 7. Min. length: 7. Input: " + JSON.stringify(instance));
}
this.actualInstance = instance;
match++;
diff --git a/samples/client/petstore/javascript-promise-es6/src/model/StringOrBoolean.js b/samples/client/petstore/javascript-promise-es6/src/model/StringOrBoolean.js
new file mode 100644
index 00000000000..029e14e41a7
--- /dev/null
+++ b/samples/client/petstore/javascript-promise-es6/src/model/StringOrBoolean.js
@@ -0,0 +1,119 @@
+/**
+ * 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: \" \\
+ *
+ * The version of the OpenAPI document: 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 StringOrBoolean model module.
+ * @module model/StringOrBoolean
+ * @version 1.0.0
+ */
+class StringOrBoolean {
+ /**
+ * Constructs a new StringOrBoolean
.
+ * String or boolean
+ * @alias module:model/StringOrBoolean
+ * @param {(module:model/Boolean|module:model/String)} instance The actual instance to initialize StringOrBoolean.
+ */
+ constructor(instance = null) {
+ if (instance === null) {
+ this.actualInstance = null;
+ return;
+ }
+ var match = 0;
+ var errorMessages = [];
+ try {
+ // validate string
+ if (!(typeof instance === 'string')) {
+ throw new Error("Invalid value. Must be string. Input: " + JSON.stringify(instance));
+ }
+ this.actualInstance = instance;
+ match++;
+ } catch(err) {
+ // json data failed to deserialize into String
+ errorMessages.push("Failed to construct String: " + err)
+ }
+
+ try {
+ // validate boolean
+ if (!(typeof instance === 'boolean')) {
+ throw new Error("Invalid value. Must be boolean. Input: " + JSON.stringify(instance));
+ }
+ this.actualInstance = instance;
+ match++;
+ } catch(err) {
+ // json data failed to deserialize into Boolean
+ errorMessages.push("Failed to construct Boolean: " + err)
+ }
+
+ if (match > 1) {
+ throw new Error("Multiple matches found constructing `StringOrBoolean` with oneOf schemas Boolean, String. Input: " + JSON.stringify(instance));
+ } else if (match === 0) {
+ this.actualInstance = null; // clear the actual instance in case there are multiple matches
+ throw new Error("No match found constructing `StringOrBoolean` with oneOf schemas Boolean, String. Details: " +
+ errorMessages.join(", "));
+ } else { // only 1 match
+ // the input is valid
+ }
+ }
+
+ /**
+ * Constructs a StringOrBoolean
from a plain JavaScript object, optionally creating a new instance.
+ * Copies all relevant properties from data
to obj
if supplied or a new instance if not.
+ * @param {Object} data The plain JavaScript object bearing properties of interest.
+ * @param {module:model/StringOrBoolean} obj Optional instance to populate.
+ * @return {module:model/StringOrBoolean} The populated StringOrBoolean
instance.
+ */
+ static constructFromObject(data, obj) {
+ return new StringOrBoolean(data);
+ }
+
+ /**
+ * Gets the actual instance, which can be Boolean
, String
.
+ * @return {(module:model/Boolean|module:model/String)} The actual instance.
+ */
+ getActualInstance() {
+ return this.actualInstance;
+ }
+
+ /**
+ * Sets the actual instance, which can be Boolean
, String
.
+ * @param {(module:model/Boolean|module:model/String)} obj The actual instance.
+ */
+ setActualInstance(obj) {
+ this.actualInstance = StringOrBoolean.constructFromObject(obj).getActualInstance();
+ }
+
+ /**
+ * Returns the JSON representation of the actual instance.
+ * @return {string}
+ */
+ toJSON = function(){
+ return this.getActualInstance();
+ }
+
+ /**
+ * Create an instance of StringOrBoolean from a JSON string.
+ * @param {string} json_string JSON string.
+ * @return {module:model/StringOrBoolean} An instance of StringOrBoolean.
+ */
+ static fromJSON = function(json_string){
+ return StringOrBoolean.constructFromObject(JSON.parse(json_string));
+ }
+}
+
+
+StringOrBoolean.OneOf = ["Boolean", "String"];
+
+export default StringOrBoolean;
+
diff --git a/samples/client/petstore/javascript-promise-es6/test/model/StringOrBoolean.spec.js b/samples/client/petstore/javascript-promise-es6/test/model/StringOrBoolean.spec.js
new file mode 100644
index 00000000000..d6c9a43bbba
--- /dev/null
+++ b/samples/client/petstore/javascript-promise-es6/test/model/StringOrBoolean.spec.js
@@ -0,0 +1,59 @@
+/**
+ * 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: \" \\
+ *
+ * The version of the OpenAPI document: 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', process.cwd()+'/src/index'], factory);
+ } else if (typeof module === 'object' && module.exports) {
+ // CommonJS-like environments that support module.exports, like Node.
+ factory(require('expect.js'), require(process.cwd()+'/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.StringOrBoolean();
+ });
+
+ 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('StringOrBoolean', function() {
+ it('should create an instance of StringOrBoolean', function() {
+ // uncomment below and update the code to test StringOrBoolean
+ //var instance = new OpenApiPetstore.StringOrBoolean();
+ //expect(instance).to.be.a(OpenApiPetstore.StringOrBoolean);
+ });
+
+ });
+
+}));