Open supervital opened 1 year ago
is it possible for you to add a discriminator
field on your union type?
"unions": {
"discriminator": "name of field you want",
"myValue": {
"types": [
]
}
}
and then try again? I'm not familiar with the dart generator so may need to contact the author of that code generator directly
is it possible for you to add a
discriminator
field on your union type?"unions": { "discriminator": "name of field you want", "myValue": { "types": [ ] } }
and then try again? I'm not familiar with the dart generator so may need to contact the author of that code generator directly
Thanks for the reply. I have just tried and it has no effect. And "discriminator" of the union, like this:
"unions": {
"myValue": {
"discriminator": "name of field you want",
"types": [
]
}
}
Looks like the dart generator doesn't work with primitive types in union. So, as a fix, I created a wrapper object for the primitive types:
{
"unions":{
"myValue":{
"types":[
{
"type":"integerValue",
"description":"Simple integer value."
},
{
"type":"doubleValue",
"description":"Simple double value."
},
{
"type":"someCustomValue",
"description":"A custom value."
},
{
"type":"someCustomValue2",
"description":"A custom value."
}
]
},
"integerValue":{
"description":"Object containing an integer.",
"fields":[
{
"name":"value",
"type":"integer"
}
]
},
"doubleValue":{
"description":"Object containing a double.",
"fields":[
{
"name":"value",
"type":"double"
}
]
}
}
}
thanks for sharing!
Hello,
I have the next union:
And while compiling I get the next error:
Error: The operator '[]' isn't defined for the class 'int'. [ +6 ms] Try correcting the operator to an existing operator, or defining a '[]' operator. [ ] factory.first((json['integer'] as int)['value']));
A part of the generated code (dart):
When I manually remove ['value'] compilation is successful.
What am I doing wrong? Thanks.