-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fixes @DDtKey ! Doesn't look like the samples compile as-is.
cd rust/client/others/rust
cargo check
nor 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
@@ -8,6 +8,7 @@ | |||
* Generated by: https://openapi-generator.tech | |||
*/ | |||
|
|||
use crate::models; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
modules/openapi-generator/src/main/resources/rust/hyper/api.mustache
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache
Outdated
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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::rename
mappings)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)oneOf
generation for client #17915 (comment)number
representation:f32
->f64
PR 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