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

spring-http-interface: introduce springHttpClientAdapter, fix paramDoc.mustache #19710

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

ibaranga
Copy link

@ibaranga ibaranga commented Sep 29, 2024

Addressing issue #19712

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

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.

@cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente @Zomzog @martin-mfg

…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.
@@ -28,7 +28,7 @@ public abstract class HttpInterfacesAbstractConfigurator {
{{#apis}}
@Bean(name = "{{configPackage}}.HttpInterfacesAbstractConfigurator.{{classVarName}}")
{{classname}} {{classVarName}}HttpProxy() {
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(webClient)).build();
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(WebClientAdapter.forClient(webClient)).build();
Copy link
Author

Choose a reason for hiding this comment

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

This is marked as deprecated, replacing it with builderFor, which is also in line with the rest of the httpInterfaces*Configuration.mustache templates

@wing328
Copy link
Member

wing328 commented Oct 1, 2024

@ibaranga
Copy link
Author

ibaranga commented Oct 1, 2024

@wing328 thanks, fixed!

@wing328 wing328 modified the milestones: 7.9.0, 7.10.0 Oct 8, 2024
@wing328
Copy link
Member

wing328 commented Oct 11, 2024

please review the errors reported by the CI when you've time.

@ibaranga
Copy link
Author

please review the errors reported by the CI when you've time.

Thanks again, @wing328, I've just updated the PR!

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.

2 participants