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

feat(rust,client): derive Default for operation parameter structs #10432

Merged

Conversation

PiDelport
Copy link
Contributor

@PiDelport PiDelport commented Sep 20, 2021

This makes operations with many parameters easier to work with.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    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*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@frol (2017/07) @farcaller (2017/08) @richardwhiuk (2019/07) @paladinzh (2020/05)

@wing328
Copy link
Member

wing328 commented Sep 21, 2021

LGTM. I assume this is a backward-compatible change. Please correct me if I'm wrong.

@PiDelport PiDelport force-pushed the feat-rust-client-params-derive-default branch from 4c6e0da to 3b5dfe2 Compare September 21, 2021 08:32
@wing328
Copy link
Member

wing328 commented Sep 22, 2021

Looks like this breaks the existing tests:

    Checking petstore-reqwest-async v1.0.0 (/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/rust/reqwest/petstore-async)
    Checking rust-test-reqwest v1.0.0 (/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/rust/reqwest/rust-test)
error[E0277]: the trait bound `Pet: Default` is not satisfied
   --> reqwest/petstore-async/src/apis/pet_api.rs:21:5
    |
18  | #[derive(Clone, Debug, Default)]
    |                        ------- in this derive macro expansion
...
21  |     pub pet: crate::models::Pet
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `Pet`
    |
note: required by `std::default::Default::default`
    = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `Pet: Default` is not satisfied
   --> reqwest/petstore-async/src/apis/pet_api.rs:57:5
    |
54  | #[derive(Clone, Debug, Default)]
    |                        ------- in this derive macro expansion
...
57  |     pub pet: crate::models::Pet
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `Pet`
    |
note: required by `std::default::Default::default`
    = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `Order: Default` is not satisfied
   --> reqwest/petstore-async/src/apis/store_api.rs:35:5
    |
32  | #[derive(Clone, Debug, Default)]
    |                        ------- in this derive macro expansion
...
35  |     pub order: crate::models::Order
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `Order`
    |
note: required by `std::default::Default::default`
    = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `User: Default` is not satisfied
   --> reqwest/petstore-async/src/apis/user_api.rs:21:5
    |
18  | #[derive(Clone, Debug, Default)]
    |                        ------- in this derive macro expansion
...
21  |     pub user: crate::models::User
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `User`
    |
note: required by `std::default::Default::default`
    = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `User: Default` is not satisfied
   --> reqwest/petstore-async/src/apis/user_api.rs:67:5
    |
62  | #[derive(Clone, Debug, Default)]
    |                        ------- in this derive macro expansion
...
67  |     pub user: crate::models::User
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `User`
    |
note: required by `std::default::Default::default`
    = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)

    Checking petstore-reqwest v1.0.0 (/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/rust/reqwest/petstore)
For more information about this error, try `rustc --explain E0277`.

Ref: https://app.travis-ci.com/github/OpenAPITools/openapi-generator/builds/238201866

Can you please take a look when you've time?

@PiDelport
Copy link
Contributor Author

Ah, that makes sense, yeah: the generated models need to derive Default too. (The spec I've been testing with doesn't hit that case.)

This makes operations with many parameters easier to work with.
@PiDelport PiDelport force-pushed the feat-rust-client-params-derive-default branch from 3b5dfe2 to 29bb2b3 Compare September 22, 2021 08:09
@PiDelport
Copy link
Contributor Author

Cool, I updated the model template (and actually tested the generated petstore samples locally, this time 😅).

@PiDelport PiDelport force-pushed the feat-rust-client-params-derive-default branch from 29bb2b3 to d5f003c Compare September 22, 2021 08:17
@PiDelport
Copy link
Contributor Author

LGTM. I assume this is a backward-compatible change. Please correct me if I'm wrong.

Yes, it is. 👍🏼

@wing328
Copy link
Member

wing328 commented Sep 23, 2021

Tests passed via https://app.travis-ci.com/github/OpenAPITools/openapi-generator/builds/238302672

@wing328 wing328 merged commit 3134258 into OpenAPITools:master Sep 23, 2021
@Foorack
Copy link
Contributor

Foorack commented Oct 27, 2021

LGTM. I assume this is a backward-compatible change. Please correct me if I'm wrong.

Seems like it wasn't. This was forgotten for Enums, so a breaking regression for us. We have had to pin Rust SDK to 5.2.0, as 5.3.0 can no longer generate the spec.

error[E0277]: the trait bound `DeveloperType: Default` is not satisfied
   --> src\models\current_user.rs:37:5
    |
12  | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
    |                                   ------- in this derive macro expansion
...
37  |     pub developer_type: crate::models::DeveloperType,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `DeveloperType`
    |
note: required by `std::default::Default::default`
   --> C:\Users\Foorack\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\default.rs:116:5
    |
116 |     fn default() -> Self;
    |     ^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `UserStatus: Default` is not satisfied
   --> src\models\current_user.rs:87:5
    |
12  | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
    |                                   ------- in this derive macro expansion
...
87  |     pub status: crate::models::UserStatus,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `UserStatus`
    |
note: required by `std::default::Default::default`
   --> C:\Users\Foorack\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\default.rs:116:5
    |
116 |     fn default() -> Self;
    |     ^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `FavoriteType: Default` is not satisfied
   --> src\models\favorite.rs:22:5
    |
12  | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
    |                                   ------- in this derive macro expansion
...
22  |     pub _type: crate::models::FavoriteType,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `FavoriteType`
    |
note: required by `std::default::Default::default`
   --> C:\Users\Foorack\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\default.rs:116:5
    |
116 |     fn default() -> Self;
    |     ^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)

wing328 pushed a commit that referenced this pull request Nov 11, 2021
* Fix breaking regression introduced by #10432

This change forgot enum structures, which causes the compiler to throw errors for "the trait `Default` is not implemented for MyEnum".
This change implements the Default trait to the enum template.

* fix: add Default for type enums
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.

None yet

3 participants