-
-
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
Fix enum types in structs #3309
Conversation
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 fix!
Just found one minor bit where you conflict with another PR's changes. Happy for this to go in once that's sorted.
Not sure what the CI failure is - it looks unrelated.
@@ -33,7 +33,7 @@ impl {{{classname}}} for {{{classname}}}Client { | |||
let configuration: &configuration::Configuration = self.configuration.borrow(); | |||
let client = &configuration.client; | |||
|
|||
let uri_str = format!("{}{{{path}}}", configuration.base_path{{#pathParams}}, {{{baseName}}}={{#isString}}urlencode({{/isString}}{{{paramName}}}{{#isListContainer}}.join(",").as_ref(){{/isListContainer}}{{#isString}}){{/isString}}{{/pathParams}}); | |||
let uri_str = format!("{}{{{path}}}", configuration.base_path{{#pathParams}}, {{{baseName}}}={{#isString}}::apis::urlencode({{/isString}}{{{paramName}}}{{#isListContainer}}.join(",").as_ref(){{/isListContainer}}{{#isString}}){{/isString}}{{/pathParams}}); |
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.
Looking at #3332, should this be crate::apis...
instead for compatibility with Rust 2018?
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.
yeah, so crate::apis::
will not work with Rust 2015. I started to switch import statements to the Rust 2018 format, but decided against it to avoid breaking changes. However, since it's already staged, I'll just wait for #3332 to be merged and rebase it.
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.
That sounds fine.
I thought crate::apis::
was compatible with Rust 2015, though? If I apply the following diff, the sample continues to compile successfully.
diff --git a/samples/client/petstore/rust-reqwest/Cargo.toml b/samples/client/petstore/rust-reqwest/Cargo.toml
index 6d66b8f7c7..25b15f54fd 100644
--- a/samples/client/petstore/rust-reqwest/Cargo.toml
+++ b/samples/client/petstore/rust-reqwest/Cargo.toml
@@ -2,6 +2,7 @@
name = "petstore_client"
version = "1.0.0"
authors = ["OpenAPI Generator team and contributors"]
+edition = "2015"
[dependencies]
serde = "^1.0"
diff --git a/samples/client/petstore/rust-reqwest/src/apis/client.rs b/samples/client/petstore/rust-reqwest/src/apis/client.rs
index ea6b0eb635..5233b3cf5d 100644
--- a/samples/client/petstore/rust-reqwest/src/apis/client.rs
+++ b/samples/client/petstore/rust-reqwest/src/apis/client.rs
@@ -15,7 +15,7 @@ impl APIClient {
APIClient {
configuration: rc.clone(),
- pet_api: Box::new(::apis::PetApiClient::new(rc.clone())),
+ pet_api: Box::new(crate::apis::PetApiClient::new(rc.clone())),
store_api: Box::new(::apis::StoreApiClient::new(rc.clone())),
user_api: Box::new(::apis::UserApiClient::new(rc.clone())),
}
I've not done much around the transition between editions, so would not be surprised if I was misunderstanding what was going on here...
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.
Actually, you're totally right, I didn't realize this. I just fixed it in a commit on top, and regenerated the 2 clients. I think you can merge both this one and #3332 independently.
EDIT: I also added a derive(PartialEq, Eq)
to the generated structs
and enum
. I need it for the integration tests where you actually interact with the server and want to assert the results.
The other PR's gone in. I'm happy to merge this once the conflicts have been fixed. |
Done! |
Great - thank you! This should go out in v4.1.0, which is due at the end of the month. |
This PR added Removing the |
Oh dear. Good catch - thanks! I've just raised #3463 to fix |
It fails if the model contains a float, which don't implement Eq. Fix for bug introduced in #3309. We really need to improve the testing of the rust generator to catch this sort of mistake in future. I don't have time to do this now, though.
@gferon thanks for the PR, which has been included in the 4.1.0 release: https://twitter.com/oas_generator/status/1160000504455319553 |
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the rust (e.g. php, ruby, python, etc) code generator or rust client's mustache templates). Windows batch files can be found in.\bin\windows\
. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.master
,4.1.x
,5.0.x
. Default:master
.Description of the PR
I already contributed proper
enum
supports a few weeks ago, but somehow missed actually using them when they're used as a property. This PR fixes that.I also took the liberty of fixing a bunch of unused warnings.
cc: @frol @farcaller @bjgill