-
Notifications
You must be signed in to change notification settings - Fork 83
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
Unions generation: The operator '[]' isn't defined for the class 'int' #894
Comments
is it possible for you to add a
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. "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.
The text was updated successfully, but these errors were encountered: