spring-http-interface: introduce springHttpClientAdapter, fix paramDoc.mustache#19710
spring-http-interface: introduce springHttpClientAdapter, fix paramDoc.mustache#19710wing328 merged 28 commits intoOpenAPITools:masterfrom
springHttpClientAdapter, fix paramDoc.mustache#19710Conversation
…mDoc.mustache` --- ### What - Introduce `springHttpClientAdapter` for `spring-http-interface` - This property is used for selecting HTTP client implementation in Spring HTTP interfaces, with separate templates for each client configuration - Added an `spring-http-interface`-specific **empty** `paramDoc.mustache` --- ### Why - Enable selecting different HTTP client implementations when generating Spring HTTP client interfaces - Provides additional flexibility for users who want to generate non-reactive Spring Boot applications. --- ### How - `springHttpClientAdapter`: Allows users to choose between different HTTP client implementations used in `HttpInterfacesAbstractConfigurator`: - `web-client` (set by default, to ensure **backward compatibility**) - `rest-client` - `rest-template` - Separate templates for each `HttpInterfacesAbstractConfigurator` implementation: - `httpInterfacesRestClientConfiguration.mustache` - `httpInterfacesRestTemplateConfiguration.mustache` - `httpInterfacesWebClientConfiguration.mustache` - Log warning for configuration mismatch - When `reactive: false` is used in combination with the reactive `web-client`, it warns users of potential configuration mismatches, and suggests switching to `rest-template` or `rest-client` for non-reactive configurations. - Remove unnecessary paramDoc - Added an `spring-http-interface`-specific **empty** `paramDoc.mustache` in `JavaSpring/libraries/spring-http-interface/paramDoc.mustache` - This prevents inheriting the `@Parameter` annotations from the default Spring template located at `JavaSpring/paramDoc.mustache`. - Otherwise, the generated code includes `@Parameter` annotations on request body parameters, which were causing compile errors due to missing imports --- ### Testing Done - **Manual testing**: Verified that the generated code uses `WebClient`, `RestTemplate`, or `RestClient` based on the value of the `springHttpClientAdapter` property. - **Tested different configurations**: - **`reactive: false` & `web-client`**: Logs a warning, suggesting the use of `rest-client` or `rest-template`. - **`springHttpClientAdapter: rest-template`**: Generates code with `RestTemplateAdapter` using the `httpInterfacesRestTemplateConfiguration.mustache`. - **`springHttpClientAdapter: web-client` (default)**: Generates code using `WebClientAdapter` from `httpInterfacesWebClientConfiguration.mustache` and ensures backward compatibility. - **Tested `paramDoc.mustache` change**: Verified that the empty `paramDoc.mustache` prevents the generation of `@Parameter` annotations on request body parameters and resolves the compile errors caused by missing imports. --- ### PR checklist - [ ] Read the [contribution guidelines](https://github.com/openapitools/openapi-generator/blob/master/CONTRIBUTING.md). - [ ] 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](https://github.com/OpenAPITools/openapi-generator#14---build-projects) 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](https://gitforwindows.org/)) 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](https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches): `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](https://github.com/openapitools/openapi-generator/#62---openapi-generator-technical-committee) members, so they are more likely to review the pull request.
| @Bean(name = "{{configPackage}}.HttpInterfacesAbstractConfigurator.{{classVarName}}") | ||
| {{classname}} {{classVarName}}HttpProxy() { | ||
| HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(webClient)).build(); | ||
| HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(WebClientAdapter.forClient(webClient)).build(); |
There was a problem hiding this comment.
This is marked as deprecated, replacing it with builderFor, which is also in line with the rest of the httpInterfaces*Configuration.mustache templates
|
please review the errors when you've time: https://github.com/OpenAPITools/openapi-generator/actions/runs/11094295717/job/30896757555?pr=19710 |
|
@wing328 thanks, fixed! |
|
please review the errors reported by the CI when you've time. |
Thanks again, @wing328, I've just updated the PR! |
|
filed #20129 to trigger all the tests let's see how that goes |
|
@ibaranga can you please add sample to test the new option similar to #20071 (comment) ? |
|
It would be good to test this with latest GA version of spring, as #20174 is related |
|
@davidkarlsen do you mind doing a test locally for that? |
|
Do you have any plans to support Kotlin?🤔 |
I just opened an issue here and plan to contribute a PR with barebones implementation of kotlin-spring declarative http interface in coming days. |
|
Hi, it seems this PR was close to being merged about a year ago, but hasn’t been updated since. |
|
@Bragolgirith can you please file a new one based on this PR with resolved merged conflicts? |
…http-interface-useHttpServiceProxyFactoryInterfacesConfigurator
…rsion (3 or 4) and fail early if unsupported
|
I wouldn't want to steal the attribution from the original PR author, so (for now) I've now created a PR to @ibaranga's fork with the following changes:
@ibaranga Would you be willing to take a look and - if at all possible - merge it soon-ish? :) |
…seHttpServiceProxyFactoryInterfacesConfigurator 19712 spring-http-interface: introduce `springHttpClientAdapter`, `fix paramDoc.mustache` - merge from master
|
Thanks @Bragolgirith - merged! |
@ibaranga will be listed as co-author in your (@Bragolgirith) PR. That's how git works. Just triggered the workflow. Will merge if all tests pass. |
…pring-http-interface`
…g)" -> "Spring 6 HTTP interfaces (testing). Requires Spring Boot 3 or 4." in java-camel.md and spring.md
Thanks @wing328 ! Just pushed a few follow-up fixes to satisfy the spring-http-interface early-checks ("Requires Spring Boot 3 or 4."):
All checks (except docker/maven publish) are passing on my fork. |
Addressing issue #19712
What
springHttpClientAdapteruseHttpServiceProxyFactoryInterfacesConfiguratorforspring-http-interfacespring-http-interface-specific emptyparamDoc.mustacheWhy
How
-springHttpClientAdapter: Allows users to choose between different HTTP client implementations used inHttpInterfacesAbstractConfigurator:-web-client(set by default, to ensure backward compatibility)-rest-client-rest-template- Separate templates for eachHttpInterfacesAbstractConfiguratorimplementation:-httpInterfacesRestClientConfiguration.mustache-httpInterfacesRestTemplateConfiguration.mustache-httpInterfacesWebClientConfiguration.mustache- Log warning for configuration mismatch- Whenreactive: falseis used in combination with the reactiveweb-client, it warns users of potential configurationmismatches, and suggests switching to
rest-templateorrest-clientfor non-reactive configurations.spring-http-interface: introduce
springHttpClientAdapter, fixparamDoc.mustache#19710 (comment)Remove unnecessary paramDoc
spring-http-interface-specific emptyparamDoc.mustacheinJavaSpring/libraries/spring-http-interface/paramDoc.mustache@Parameterannotations from the default Spring template located atJavaSpring/paramDoc.mustache.@Parameterannotations on request body parameters, which were causing compile errors due to missing importsPR checklist
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.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)@cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente @Zomzog @martin-mfg