William Cheng 9cc23dd09d
[JavaScript] add oneOf support (#13561)
* JS add oneOf support

* add validate json method

* add oneOf support to JS client

* update samples

* add todo in anyof

* switch to composed.oneOf

* update oneOf to support primitive types

* update messages

* minor fix, add more tests

* update samples

* fix npe in from model

* fix syntax error in length check

* update samples
2022-10-02 13:34:50 +08:00

113 lines
3.7 KiB
JavaScript

/**
* 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';
import ReadOnlyFirst from './ReadOnlyFirst';
/**
* The ArrayTest model module.
* @module model/ArrayTest
* @version 1.0.0
*/
class ArrayTest {
/**
* Constructs a new <code>ArrayTest</code>.
* @alias module:model/ArrayTest
*/
constructor() {
ArrayTest.initialize(this);
}
/**
* 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) {
}
/**
* Constructs a <code>ArrayTest</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/ArrayTest} obj Optional instance to populate.
* @return {module:model/ArrayTest} The populated <code>ArrayTest</code> instance.
*/
static constructFromObject(data, obj) {
if (data) {
obj = obj || new ArrayTest();
if (data.hasOwnProperty('array_of_string')) {
obj['array_of_string'] = ApiClient.convertToType(data['array_of_string'], ['String']);
}
if (data.hasOwnProperty('array_array_of_integer')) {
obj['array_array_of_integer'] = ApiClient.convertToType(data['array_array_of_integer'], [['Number']]);
}
if (data.hasOwnProperty('array_array_of_model')) {
obj['array_array_of_model'] = ApiClient.convertToType(data['array_array_of_model'], [[ReadOnlyFirst]]);
}
}
return obj;
}
/**
* Validates the JSON data with respect to <code>ArrayTest</code>.
* @param {Object} data The plain JavaScript object bearing properties of interest.
* @return {boolean} to indicate whether the JSON data is valid with respect to <code>ArrayTest</code>.
*/
static validateJSON(data) {
// ensure the json data is an array
if (!Array.isArray(data['array_of_string'])) {
throw new Error("Expected the field `array_of_string` to be an array in the JSON data but got " + data['array_of_string']);
}
// ensure the json data is an array
if (!Array.isArray(data['array_array_of_integer'])) {
throw new Error("Expected the field `array_array_of_integer` to be an array in the JSON data but got " + data['array_array_of_integer']);
}
// ensure the json data is an array
if (!Array.isArray(data['array_array_of_model'])) {
throw new Error("Expected the field `array_array_of_model` to be an array in the JSON data but got " + data['array_array_of_model']);
}
return true;
}
}
/**
* @member {Array.<String>} array_of_string
*/
ArrayTest.prototype['array_of_string'] = undefined;
/**
* @member {Array.<Array.<Number>>} array_array_of_integer
*/
ArrayTest.prototype['array_array_of_integer'] = undefined;
/**
* @member {Array.<Array.<module:model/ReadOnlyFirst>>} array_array_of_model
*/
ArrayTest.prototype['array_array_of_model'] = undefined;
export default ArrayTest;