-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[js] fix boolean in oneOf, add tests (#14380)
- Loading branch information
Showing
24 changed files
with
646 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
samples/client/petstore/javascript-apollo/docs/StringOrBoolean.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# OpenApiPetstore.StringOrBoolean | ||
|
||
## Properties | ||
|
||
Name | Type | Description | Notes | ||
------------ | ------------- | ------------- | ------------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
samples/client/petstore/javascript-apollo/src/model/StringOrBoolean.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <code>StringOrBoolean</code>. | ||
* 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 <code>StringOrBoolean</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/StringOrBoolean} obj Optional instance to populate. | ||
* @return {module:model/StringOrBoolean} The populated <code>StringOrBoolean</code> instance. | ||
*/ | ||
static constructFromObject(data, obj) { | ||
return new StringOrBoolean(data); | ||
} | ||
|
||
/** | ||
* Gets the actual instance, which can be <code>Boolean</code>, <code>String</code>. | ||
* @return {(module:model/Boolean|module:model/String)} The actual instance. | ||
*/ | ||
getActualInstance() { | ||
return this.actualInstance; | ||
} | ||
|
||
/** | ||
* Sets the actual instance, which can be <code>Boolean</code>, <code>String</code>. | ||
* @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; | ||
|
59 changes: 59 additions & 0 deletions
59
samples/client/petstore/javascript-apollo/test/model/StringOrBoolean.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
|
||
}); | ||
|
||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
samples/client/petstore/javascript-es6/docs/StringOrBoolean.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# OpenApiPetstore.StringOrBoolean | ||
|
||
## Properties | ||
|
||
Name | Type | Description | Notes | ||
------------ | ------------- | ------------- | ------------- | ||
|
||
|
Oops, something went wrong.