fix(rust): oneOf generation for client#17915
Conversation
Discriminator mapping has been ignored in some cases. Even existing samples had wrong definition in some cases This PR addresses this
Solves OpenAPITools#17869 and OpenAPITools#17896 and also includes unmerged $17898 Unfortunately it affects quite a lot of code, but we can see that only client-side models were affected by re-generation. I tried to split this PR to several, but they're really coupled and hard to create a chain of PRs.
|
But JFYI, it generates the following enum against example in that PR: /// Either an account name or an email.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AccountOrEmail {
/// An email address.
Email(Box<String>),
/// An account name.
AccountName(Box<String>),
} |
There was a problem hiding this comment.
Thanks for the fixes @DDtKey ! Doesn't look like the samples compile as-is.
cd rust/client/others/rust
cargo checknor does the cli compile
docker build .
Will look at it in-depth tomorrow to help this along, though we'll still need approval from rust maintainers
...es/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java
Outdated
Show resolved
Hide resolved
|
There were missing changes, sorry
UPD: however I see issues for |
70976e5 to
671003b
Compare
| * Generated by: https://openapi-generator.tech | ||
| */ | ||
|
|
||
| use crate::models; |
There was a problem hiding this comment.
A lot of client files contain only such changes - it's now aligned with server-side generators (via AbstractRustCodegen).
Also indentation is fixed in models (used to be too many extra blank lines)
| @Override | ||
| public String getTypeDeclaration(Schema p) { |
There was a problem hiding this comment.
It was error-prone because almost copy-paste between rust-generators, so only extracted to AbstractRustCodegen and unified with client .
We can see that only client samples were affected by this PR.
|
PR is ready for review, cleaned-up the code a bit |
678c671 to
401bedb
Compare
That looks good to me! It's not obvious to me why the Thank you very much for this PR! ❤️ |
Yeah, also find this confusing. |
|
Just pushed one more improvement:
"Fruit": {
"type": "object",
"oneOf": [
{
"$ref": "#/components/schemas/Apple"
},
{
"$ref": "#/components/schemas/Apple"
}
],
"discriminator": {
"propertyName": "kind",
"mapping": {
"red_apple": "#/components/schemas/Apple",
"green_apple": "#/components/schemas/Apple"
}
}
},The result is the following: #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "kind")]
pub enum Fruit {
RedApple(Box<models::Apple>),
GreenApple(Box<models::Apple>),
}UPD: added test coverage for this |
...es/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java
Show resolved
Hide resolved
...es/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java
Show resolved
Hide resolved
...es/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java
Outdated
Show resolved
Hide resolved
...es/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java
Show resolved
Hide resolved
ctrlaltf24
left a comment
There was a problem hiding this comment.
concerns addressed, LGTM. Works with my openapi definition that motivated the original change.
Thanks @DDtKey !
|
thanks for the PR. please review the build failure when you've time, e.g. https://github.com/OpenAPITools/openapi-generator/actions/runs/7996641152/job/21865620537?pr=17915 |
|
Ouch, sorry, my bad - there is no such method for the interface, but only for a particular type. Fixed, build works as expected (at least locally) |
|
lgtm. let's give it a try have a nice weekend |
* fix(rust): discriminator mapping to serde rename Discriminator mapping has been ignored in some cases. Even existing samples had wrong definition in some cases This PR addresses this * fix(rust): `oneOf` generation for client Solves OpenAPITools#17869 and OpenAPITools#17896 and also includes unmerged $17898 Unfortunately it affects quite a lot of code, but we can see that only client-side models were affected by re-generation. I tried to split this PR to several, but they're really coupled and hard to create a chain of PRs. * fix: indentation in `impl Default` * missing fixes * fix: correct typeDeclaration with unaliased schema * style: improve indentation for models * fix: user toModelName for aliases of oneOf * refactor: unify `getTypeDeclaration` for rust * cover the case when `mapping` has the same `ref` for different mapping names * test: add test for previous change * style: remove extra qualified path to models * add some comments * fix(build): use method of `List` instead of specific for `LinkedList`
Closes #17869, #17896, #9497 and also includes unmerged #17898 (fix of
serde::renamemappings)Unfortunately it affects quite a lot of code, but we can see that only client-side models were affected by re-generation.
I tried to split this PR to several, but they're really coupled and hard to create a chain of PRs (e.g #14898 & #17899 and issue with imports).
Other changes:
AbstractRustCodegen(it used to be error-prone copy/paste with small differences for server & client)oneOfgeneration for client #17915 (comment)numberrepresentation:f32->f64PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming 7.1.0 minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)@frol @farcaller @richardwhiuk @paladinzh @jacob-pro