Skip to content
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

Merged
merged 5 commits into from
Jul 24, 2019
Merged

Conversation

gferon
Copy link
Contributor

@gferon gferon commented Jul 8, 2019

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./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.
  • Filed the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

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

Copy link
Contributor

@bjgill bjgill left a 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}});
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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...

Copy link
Contributor Author

@gferon gferon Jul 17, 2019

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.

@bjgill
Copy link
Contributor

bjgill commented Jul 18, 2019

The other PR's gone in. I'm happy to merge this once the conflicts have been fixed.

@gferon
Copy link
Contributor Author

gferon commented Jul 22, 2019

The other PR's gone in. I'm happy to merge this once the conflicts have been fixed.

Done!

@bjgill bjgill added this to the 4.1.0 milestone Jul 24, 2019
@bjgill
Copy link
Contributor

bjgill commented Jul 24, 2019

Great - thank you! This should go out in v4.1.0, which is due at the end of the month.

@bjgill bjgill merged commit 2e81e61 into OpenAPITools:master Jul 24, 2019
@antonafMSFT
Copy link

This PR added Eq and PartialEq to generated structs, which produces source that won't build when a struct contains eg an f32 field.
Rust intentionally doesn't implement Eq for float types.

Removing the Eq derivations and leaving only the PartialEq works, however.

@bjgill bjgill mentioned this pull request Jul 25, 2019
4 tasks
@bjgill
Copy link
Contributor

bjgill commented Jul 25, 2019

Oh dear. Good catch - thanks!

I've just raised #3463 to fix

bjgill added a commit that referenced this pull request Jul 29, 2019
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.
@wing328
Copy link
Member

wing328 commented Aug 10, 2019

@gferon thanks for the PR, which has been included in the 4.1.0 release: https://twitter.com/oas_generator/status/1160000504455319553

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants