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

Added support for a trait based reqwest Rust client #19788

Merged
merged 7 commits into from
Oct 30, 2024

Conversation

ranger-ross
Copy link
Contributor

This PR added a new reqwest-trait generator that was requested in #11319.

This implementation uses traits as the primary interface using APIs. This has 2 primary benefits

  • We do not need to pass configuration::Configuration to all API calls as we now store that in the implementing struct.
  • This makes mocking in tests much easier as we can implement the interface to return the desired response.

I also added 2 small QoL features in this sub-library:

  • Added a mockall option (defaults to OFF) that adds the mockall crate to make testing much easier.
  • Added a topLevelApiClient option (defaults to OFF) that adds a top level Api trait and ApiClient struct that serves a container. This makes managing APIs with many tags much easier as we only need to construct one client instead of many.

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/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (For Windows users, please run the script in Git BASH)
    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*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@wing328
Copy link
Member

wing328 commented Oct 9, 2024

https://github.com/OpenAPITools/openapi-generator/actions/runs/11200379712/job/31224911798?pr=19788

not related to this change

{{/reqwestTrait}}

[features]
{{#mockall}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about putting [features] inside the mockall mustache tags?

Copy link
Contributor Author

@ranger-ross ranger-ross Oct 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wing328 I thought about that originally, but figured it would be easier to always add [features] so adding new features in the future would be easier.

ie.

[features]
{{#mockall}}
mockall = ["dep:mockall"]
{{/mockall}}
{{#foo}}
foo = ["dep:foo"]
{{/foo}}
{{#bar}}
bar = ["dep:bar"]
{{/bar}}

But I do not have a strong opinion on this, we can change if there is a reason to 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's ok. i may file a PR later to update it

@wing328 wing328 added this to the 7.10.0 milestone Oct 9, 2024
@TroyKomodo
Copy link
Contributor

TroyKomodo commented Oct 18, 2024

Is there plan to support the useSingleRequestParameter option?

Using the reqwest-trait library vs reqwest library

image

image

Perhaps we should also look to use some sort of builder to build the structs too. Not sure if in scope. (not all options are required)

@TroyKomodo
Copy link
Contributor

I went ahead and added support for the 2 things I need:

  • single arguments
  • builder on that single argument

changes.patch

@ranger-ross
Copy link
Contributor Author

@TroyKomodo Thanks!
I reviewed your PR and it looks good to me. I merged it into this PR 👍

@wing328
Copy link
Member

wing328 commented Oct 22, 2024

can you please commit the updated samples and docs one more time?

@ranger-ross
Copy link
Contributor Author

can you please commit the updated samples and docs one more time?

Sure, I just pushed a commit rebuilding them. 👍

@wing328
Copy link
Member

wing328 commented Oct 30, 2024

thanks for the PR

let's give it a try to see if the community has any feedback/suggestion on this new generator

@wing328 wing328 merged commit 4a21dea into OpenAPITools:master Oct 30, 2024
20 checks passed
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.

3 participants