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

[Rust] Handle optional and nullable parameters #4016

Merged
merged 8 commits into from
Oct 15, 2019

Conversation

bcourtine
Copy link
Contributor

@bcourtine bcourtine commented Oct 1, 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 {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} 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.

/cc @jonahgeorge @wing328 @frol @farcaller @bjgill @richardwhiuk

Description of the PR

Fix #3052. This PR is based on @jonahgeorge work. It follows (and replace) PR #3250.

This PR includes theses changes:

  • Handling "optional" parameters is not optional anymore. Handling an additional parameter for it makes templates more complicated, and IMO, it is not worth it (as discussed in issue, it is an "acceptable" breaking change).
  • Optional parameters are handled everywhere: path params, query params, form params... Generated sample code compiles (both hyper and reqwest libraries).
  • For now, nullable attribut is not handled.

Jonah George and others added 5 commits June 30, 2019 08:00

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tagliala Geremia Taglialatela
As stated in OpenAPITools#3250

* Making this optinal gives more complicated templates, harder to maintain.
* Such breaking change is acceptable, since it's more a behavior correction.
Generated sample code compiles (with both Reqwest/Hyper).
Optional path parameters have no meaning. So we just call `unwrap()` in this case.
@bcourtine
Copy link
Contributor Author

Just noticed I forgot to update generated markdown documentation, to reflect new optional types. I will correct that soon.

@bcourtine
Copy link
Contributor Author

This version looks good to me: you can review it.

@bcourtine bcourtine changed the title [Rust] Handle optional parameters [Rust] [Fix #3052] Handle optional and nullable parameters Oct 2, 2019
borsboom added a commit to borsboom/ynab-api that referenced this pull request Oct 6, 2019
This patch includes:
- Handle optional parameters [#4016](OpenAPITools/openapi-generator#4016)
- Export type modules so that enums can be accessed [#4079](OpenAPITools/openapi-generator#4079)
- Derive `Clone` and `Copy` for enums
- Fix warnings: "trait objects without an explicit `dyn` are deprecated"
borsboom added a commit to borsboom/ynab-api that referenced this pull request Oct 9, 2019
This patch includes:
- Add all missing explicit dyn to trait types to remove warnings
  OpenAPITools/openapi-generator#3895
- Add missing re-export for properties that are enum
  OpenAPITools/openapi-generator#3895
- Handle optional parameters
  OpenAPITools/openapi-generator#4016
- Derive more traits
  borsboom/openapi-generator@4e3bc31
borsboom added a commit to borsboom/ynab-api that referenced this pull request Oct 9, 2019
Built using
borsboom/openapi-generator@4e3bc31

This patch includes:
- Add all missing explicit dyn to trait types to remove warnings
  OpenAPITools/openapi-generator#3895
- Add missing re-export for properties that are enum
  OpenAPITools/openapi-generator#3895
- Handle optional parameters
  OpenAPITools/openapi-generator#4016
- Derive more traits
  borsboom/openapi-generator@4e3bc31
@bcourtine
Copy link
Contributor Author

Pinging @bjgill and/or @richardwhiuk for a review.

Merging master regularly to resolve conflicts with others Rust evolutions is not a very interesting activity…

@borsboom
Copy link
Contributor

👍 I've needed and been using this PR for a project I'm working on, would love to see it merged too.

@bjgill
Copy link
Contributor

bjgill commented Oct 10, 2019

I should be able to take a look tomorrow.

Has all the merging gone OK? I can see an awful lot of .kt files that don't look as if they belong here...

@bcourtine
Copy link
Contributor Author

@bjgill Last merge looks ok... but maybe a previous one (or a commit) was not. Do you have a ".kt" file example that should not be here to verify where it comes from?

@bcourtine
Copy link
Contributor Author

@bjgill I verified the commits and you are right: theses files were added during the second merge with "master".

To correct that, I am going to revert the two last merge commits, and do a new clean merge from master.

@bcourtine bcourtine force-pushed the optional_parameters_3052 branch from 303d247 to e0601bd Compare October 11, 2019 07:16
@bcourtine
Copy link
Contributor Author

@bjgill It should be much better now.

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.

I've had a look. This is indeed a breaking change. However, I agree that the previous handling of optional parameters was very wrong, and so we're fine to do the breaking.

It looks as if this won't handle things that are both optional and nullable, but that seems like a rather niche feature that we don't need to add now.

Nothing jumps out at me, so I think we're good to go. Thanks for the contribution!

@bjgill bjgill merged commit dd08ea7 into OpenAPITools:master Oct 15, 2019
@bcourtine bcourtine deleted the optional_parameters_3052 branch October 16, 2019 09:31
@bcourtine
Copy link
Contributor Author

@bjgill Thanks for the merge!

For me (but I may have a bad comprehension of theses attributes), both Optional and Nullable should be treated as "Optional".

The only distinction I see is for a "required nullable" attribute. It must be serialized with null, whereas a null optional attribute can simply be omitted. It is handled in models, with serde skip_serialization_if attribute, set only for optional attributes.

@wing328 wing328 added this to the 4.2.0 milestone Oct 30, 2019
@wing328 wing328 changed the title [Rust] [Fix #3052] Handle optional and nullable parameters [Rust] Handle optional and nullable parameters Oct 30, 2019
@wing328
Copy link
Member

wing328 commented Oct 31, 2019

@bcourtine thanks for the PR, which has been included in v4.2.0 release: https://twitter.com/oas_generator/status/1189824932345069569

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.

[BUG][Rust] Optional query parameters are always sent
4 participants