-
-
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
Add enum support to rust
and skip none option serialization in clients
#2244
Conversation
Looks like I can't add reviewers myself, so tagging @frol, @farcaller or @bjgill to get a review. |
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 PR ❤️
A couple of minor comments, but nothing serious.
I don't know what our enums used to look like. I don't suppose you could post an example from your testing of what enum variable names now look like once they've been through toEnumVarName
?
Edit: Sorry - I was getting confused as to what the camelize
function does. Please ignore ^
Thanks for the comments @bjgill, I just made fixes for both. I think we'll start using rust generated clients a bit more, so you'll probably hear again from me! |
@gferon can you please run |
@wing328 done, though I'm now trying to understand why the |
@gferon are you free for a quick chat (IM) to discuss the issue via https://gitter.im (ID: wing328) or other channels today? |
Both OpenAPI 2.0 and 3.0 spec support enum. Can you elaborate on the issue? |
92f7943
to
097a7c4
Compare
@wing328 I'm very sorry about the time it took me to get back to this one. I believe the latest stage is the one I wanted to achieve :) feel free to review again. |
Also: * Skip serializing a field with serde if it's optional and empty * Fix borrow checker error when using &std::path::Path (should be std::path::PathBuf) * Add script to generate sample with rust-reqwest * Regenerate petstore sample for both rust targets * Remove go code from RDME.md
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.
Sorry for the delay in re-reviewing. LGTM.
tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token) | ||
auth := context.WithValue(oauth2.NoContext, sw.ContextOAuth2, tokenSource) | ||
r, err := client.Service.Operation(auth, args) | ||
cargo doc --open |
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.
❤️ the docs updates!
I'm just checking that the samples are still up to date, and then I'll merge. |
@bjgill thanks for reviewing and merging the PR 👍 |
…to inline-resolver * 'master' of github.com:OpenAPITools/openapi-generator: (213 commits) Idiomatic Rust returns for Error conversions (OpenAPITools#2812) Add API timeout handling (OpenAPITools#3078) Import inner items for map (OpenAPITools#3123) update core team in pom.xml (OpenAPITools#3126) [gradle] Document consuming via gradle plugin portal (OpenAPITools#3125) Bump up babel-cli version to fix security alert (OpenAPITools#3121) [C++] [cpprestsdk] Add examples and test for cpprestsdk (OpenAPITools#3109) Add enum support to `rust` and skip none option serialization in clients (OpenAPITools#2244) Add/update new core team member: etherealjoy (OpenAPITools#3116) Gradle sample on travis (OpenAPITools#3114) [typescript-fetch] add bearer token support (OpenAPITools#3097) Add Q_DECLARE_METATYPE to the generated models and remove ref in signals (OpenAPITools#3091) [Java][okhttp-gson] Update dependencies (OpenAPITools#3103) Link query parameter to model object (OpenAPITools#2710) scala-play-server: fix enum names for reserved words (OpenAPITools#3080) Add @Sunn to openapi generator core team (OpenAPITools#3105) fix NPE in go generator (OpenAPITools#3104) scala-play-server: fix API doc url (OpenAPITools#3096) [maven-plugin] fix strictSpec parameter without alias (OpenAPITools#3095) Ruby: Avoid double escaping path items (OpenAPITools#3093) ... # Conflicts: # modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java # modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java
Thanks again for the PR, which has been included in the v4.0.2 release: https://twitter.com/oas_generator/status/1141610197766426626 |
* Add support for the `discriminator` feature of OpenAPI 3, and implement it with `enum` in Rust * Add all missing explicit `dyn` to trait types to remove warnings * Add missing re-export for properties that are enum (was missing from #2244).
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
,./bin/security/{LANG}-petstore.sh
and./bin/openapi3/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.master
,. Default:3.4.x
,4.0.x
master
.Description of the PR
While generating rust clients, I got blocked by two issues, so here are the fixes.
The first commit adds a
serde
attribute to skip serialization if an optional field is unset - which means the field will be omitted instead of having"option": null
in the request. This is desirable because on the other-side, null is not a valid value.The second commit adds support for
enum
generation (the facilities to format name and values was already there in `RustClientCodegen.java) with a change to casing to be more rust-y.