-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REQ][Javascript] BOUNTY oneOf support in javascript client generator #13539
Comments
Thanks for sponsoring the fix. May I know if you have a spec handy to reproduce the issue and validate the fix? (the spec can help clearly define the scope of the fix) UPDATE: working on it. |
Hi, really appreciate the quick turnaround on this. I will take a closer look this weekend and make sure it works for us. If you want to look at our raw schema, you can access it at https://cloud.tator.io/schema. Sorry that schema is so huge, the model I would point you to is |
I assume the oneOf schemas are models instead of primitive types. I'll add primitive type support over the weekend. |
@jrtcppv I've pushed more changes to support your use case with
Please give it a try to see if that's what you're expecting. |
@wing328 The generated output in the Also, I tried building your branch from source and generating the client using our schema, and it doesn't look like either of those! I am invoking it as follows after building with
And the contents of
Let me know if I am doing something wrong there, I don't see any schema check in |
I've not yet updated the javascript-promise-es6 samples in my previous commit. Just pushed the updated samples via 61378ff |
Using the spec in https://cloud.tator.io/schema, I got NPE:
I'm investigating why. Are you using that as well? Just want to make sure we're using the same spec. UPDATE: NPE fixed via 215fbc5 |
Yes forgot to mention that I had to delete |
I've used your spec and pushed the auto-generated JS client to a repo. Here is what Color.js looks like: https://github.com/wing328/tator-js-client/blob/main/src/model/Color.js Let's another minor issue that I just discovered and working on a fix now. |
Just pushed our another fix. Now npm install and test run without issue in https://github.com/wing328/tator-js-client/
|
Heads up: I'm going to add a |
Wow this looks great! The Is there a dev guide on how to run I will PM you for payment instructions. Thanks again, can't say how much we appreciate the quick turnaround and thorough work. |
We already override toJSON in the oneOf models to make it works seamlessly with the Let me brainstorm a bit more to see what we can do to make JS developer life easier when consuming the auto-generated JS SDK. |
We don't have an official dev guide at the moment. We usually show some examples on how to use the openapi-generator-cli via the JAVA JAR or the Docker image. If you need help on that, please PM me. |
UPDATE: I've merged #13561 into master. I'll work on |
UPDATE: I've filed 2 more follow-up PRs For adding a method to convert an object into JSON string, I've looked into some popular JS libraries and none of them offer such method. My guess is that JS developers get used to the UPDATE: both PRs have been merged. |
@wing328 I tried using this in our application and there appears to be a problem handling certain combinations of string and other types. One of the components in our schema AttributeValue includes strings, booleans, numbers, or numerical arrays, and the generated output looks like the following: /**
* Tator REST API
* Interface to the Tator backend.
*
* The version of the OpenAPI document: v1
*
*
* 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 AttributeValue model module.
* @module model/AttributeValue
* @version 0.0.5
*/
class AttributeValue {
/**
* Constructs a new <code>AttributeValue</code>.
* Boolean, integer, float, string, datetime, [lon, lat], float array.
* @alias module:model/AttributeValue
* @param {(module:model/Boolean|module:model/Number|module:model/String|module:model/[Number])} instance The actual instance to initialize AttributeValue.
*/
constructor(instance = null) {
if (instance === null) {
this.actualInstance = null;
return;
}
var match = 0;
var errorMessages = [];
try {
this.actualInstance = instance;
match++;
} catch(err) {
// json data failed to deserialize into Boolean
errorMessages.push("Failed to construct Boolean: " + err)
}
try {
// validate array of string
if (!(typeof instance === 'number' && instance % 1 != 0)) {
throw new Error("Invalid array items. Must be number. Input: " + JSON.stringify(instance));
}
this.actualInstance = instance;
match++;
} catch(err) {
// json data failed to deserialize into Number
errorMessages.push("Failed to construct Number: " + err)
}
try {
// validate array of string
if (!(typeof instance === 'string')) {
throw new Error("Invalid input. 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 array data type
if (!Array.isArray(instance)) {
throw new Error("Invalid data type. Expecting array. Input: " + instance);
}
if (instance.length < 1) {
throw new Error("Invalid array size. Minimim: 1. Input: " + instance);
}
// validate array of string
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));
}
}
this.actualInstance = instance;
match++;
} catch(err) {
// json data failed to deserialize into [Number]
errorMessages.push("Failed to construct [Number]: " + err)
}
if (match > 1) {
throw new Error("Multiple matches found constructing `AttributeValue` with oneOf schemas Boolean, Number, String, [Number]. 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 `AttributeValue` with oneOf schemas Boolean, Number, String, [Number]. Details: " +
errorMessages.join(", "));
} else { // only 1 match
// the input is valid
}
}
/**
* Constructs a <code>AttributeValue</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/AttributeValue} obj Optional instance to populate.
* @return {module:model/AttributeValue} The populated <code>AttributeValue</code> instance.
*/
static constructFromObject(data, obj) {
return new AttributeValue(data);
}
/**
* Gets the actaul instance, which can be <code>Boolean</code>, <code>Number</code>, <code>String</code>, <code>[Number]</code>.
* @return {(module:model/Boolean|module:model/Number|module:model/String|module:model/[Number])} The actual instance.
*/
getActualInstance() {
return this.actualInstance;
}
/**
* Sets the actaul instance, which can be <code>Boolean</code>, <code>Number</code>, <code>String</code>, <code>[Number]</code>.
* @param {(module:model/Boolean|module:model/Number|module:model/String|module:model/[Number])} obj The actual instance.
*/
setActualInstance(obj) {
this.actualInstance = AttributeValue.constructFromObject(obj).getActualInstance();
}
/**
* Returns the JSON representation of the actual intance.
* @return {string}
*/
toJSON = function(){
return this.getActualInstance();
}
/**
* Create an instance of AttributeValue from a JSON string.
* @param {string} json_string JSON string.
* @return {module:model/AttributeValue} An instance of AttributeValue.
*/
static fromJSON = function(json_string){
return AttributeValue.constructFromObject(JSON.parse(json_string));
}
}
AttributeValue.OneOf = ["Boolean", "Number", "String", "[Number]"];
export default AttributeValue; However when I attempt to create an AttributeValue instance using a string I get an error. It seems to work okay for the other types in the console: |
Excellent, thank you! I will try again in the next release. |
PR merged. Please give the snapshot version a try when you've time: |
Is your feature request related to a problem? Please describe.
As already discussed in issue #10514,
anyOf
,allOf
, andoneOf
schema features are unsupported in most client generators. Our team needs support for theoneOf
feature in the Javascript generator.Describe the solution you'd like
Client side input and output checks on models that include
oneOf
in their definitions.Describe alternatives you've considered
Not using
oneOf
for validation.Additional context
Following in the footsteps of #10812, offering $1000 (USD) and gratitude to anyone who resolves this.
The text was updated successfully, but these errors were encountered: