Added support for a trait based reqwest Rust client
This PR added a new reqwest-trait generator that was requested in https://github.com/OpenAPITools/openapi-generator/issues/11319.
This implementation uses traits as the primary interface using APIs. This has 2 primary benefits
- We do not need to pass
configuration::Configurationto 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
mockalloption (defaults to OFF) that adds the mockall crate to make testing much easier. - Added a
topLevelApiClientoption (defaults to OFF) that adds a top levelApitrait andApiClientstruct 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
- [x] Read the contribution guidelines.
- [x] 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.
- [x] Run the following to build the project and update samples:
(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./mvnw clean package ./bin/generate-samples.sh ./bin/configs/*.yaml ./bin/utils/export_docs_generators.sh./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. - [x] File the PR against the correct branch:
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks) - [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 @farcaller @richardwhiuk @paladinzh @jacob-pro
https://github.com/OpenAPITools/openapi-generator/actions/runs/11200379712/job/31224911798?pr=19788
not related to this change
Is there plan to support the useSingleRequestParameter option?
Using the reqwest-trait library vs reqwest library
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)
I went ahead and added support for the 2 things I need:
- single arguments
- builder on that single argument
@TroyKomodo Thanks! I reviewed your PR and it looks good to me. I merged it into this PR :+1:
can you please commit the updated samples and docs one more time?
can you please commit the updated samples and docs one more time?
Sure, I just pushed a commit rebuilding them. :+1:
thanks for the PR
let's give it a try to see if the community has any feedback/suggestion on this new generator