You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What's the actual output vs expected output?
expected output: Calling for the DefaultApi.get_user_info() passes
actual output:
ValueError: Base failed to lookup discriminator value from {"_typeName": "string", "_value": "some string"}. Discriminator property name: _typeName, mapping: {"string": "PrimitiveString", "Info": "Info"}
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Although I have a mapping "string": "PrimitiveString", but still failed to lookup discriminator value from {"_typeName": "string", "_value": "some string"}.
The root cause is there is a bug to get the object_type in in the from_dict of base model, it should be "string" instead of "PrimitiveString", causing the failure of mapping.
This is from_dict of base model generated:
@classmethoddeffrom_dict(cls, obj: Dict[str, Any]) ->Optional[Union[PrimitiveString, Info]]:
"""Create an instance of Base from a dict"""# look up the object type based on discriminator mappingobject_type=cls.get_discriminator_value(obj)
ifobject_type=='string':
returnimport_module("openapi_client.models.primitive_string").PrimitiveString.from_dict(obj)
ifobject_type=='Info':
returnimport_module("openapi_client.models.info").Info.from_dict(obj)
raiseValueError("Base failed to lookup discriminator value from "+json.dumps(obj) +". Discriminator property name: "+cls.__discriminator_property_name+", mapping: "+json.dumps(cls.__discriminator_value_class_map))
Bug Report Checklist
expected output: Calling for the DefaultApi.get_user_info() passes
actual output:
Description
Although I have a mapping "string": "PrimitiveString", but still failed to lookup discriminator value from {"_typeName": "string", "_value": "some string"}.
The root cause is there is a bug to get the object_type in in the from_dict of base model, it should be "string" instead of "PrimitiveString", causing the failure of mapping.
This is from_dict of base model generated:
openapi-generator version
Latest master code 25/04/2024
OpenAPI declaration file content or url
Generation Details
Enable REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true
Steps to reproduce
run a server to response like:
{
"_typeName": "Info",
"val": {
"_typeName": "string",
"_value": "some string"
}
}
call get_user_info() API
Related issues/PRs
Suggest a fix
When generating the discriminator model, should have some fix to make the mapping available.
The text was updated successfully, but these errors were encountered: