-
-
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
[BUG] [rust-client] oneOf
is mapped into a struct instead of enum
#9497
Comments
oneOf
is mapped into a struct instead of enumoneOf
is mapped into a struct instead of enum
In case it's useful, the client generated by the |
thanks for that @richardwhiuk but I've just tried and issues are the same. Models generated are not correct |
@cortopy I encounter the same error. However in the openapi.json format, only this one that uses oneOf generated a combined struct instead of enum. |
ran into this problem tonight: here's the rundown from my perspective: zerotier/zeronsd#126 (comment) |
Add support for `title` property ([OpenAPI Schema title](https://swagger.io/specification/#schema-object)) for struct and enum `Component` properties. The title is useful for enums because currently the generator for rust clients created a struct for each variant and name them like: my_enum_one_of_1 my_enum_one_of_2 etc So with the title you can at least control the name of each variant structure. There is an open issue to actually produce an enum but it's not been worked on for a while OpenAPITools/openapi-generator#9497.
Bug Report Checklist
Description
oneOf
support for models is broken for rust-client. Serde will always fail when parsing responses that contain a model withoneOf
openapi-generator version
5.1.1 and also tested with master
OpenAPI declaration file content or url
https://raw.githubusercontent.com/ory/sdk/master/spec/kratos/v0.6.2-alpha.1.json
There are two problematic cases of
oneOf
in that specThe first one is a case in which all possible values are json scalar values. For example:
gets trasnformed into
but this is wrong because
UiNodeInputAttributesValue
is not a struct.My hack for this particular case is to use:
However, this does not solve all cases, since
oneOf
can also be used with references to other schemas. Indeed, there is another problematic case in this spec:Since this is a valid spec and all the models are present, the files for each type of
uiNodeAttributes
is created ok and accurately. However, the generated code foruiNodeAttributes
is incorrect. The output result merges all properties like:But this is extremely problematic and wrong, as that struct will never exist.
UiNodeAttributes
is assumed to have ALL properties from the polymorphic types. Since each of those types have different required properties, theUiNodeAttributes
assumes that ALL required properties will always exist, which will never happen.Generation Details
Steps to reproduce
Run the command above
Related issues/PRs
#2244 added support for multiple response types, but not for
oneOf
Suggest a fix
Ideally, the generated code should generate Rust
enums
in the same way that polymorphism is treated with response errorsAnother solution could be to continue merging all possible properties but make them all
Option
The accepted answer in https://stackoverflow.com/questions/37561593/how-can-i-use-serde-with-a-json-array-with-different-objects-for-successes-and-e summarises the two possibilities
The text was updated successfully, but these errors were encountered: