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

SingleRequestParameter setter parameter construction #20679

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

Conversation

Mattias-Sehlstedt
Copy link

@Mattias-Sehlstedt Mattias-Sehlstedt commented Feb 18, 2025

fix #20668

Introduces so that the argument class which is generated for useSingleRequestParameter can be constructed similar to the POJO models. The implementation uses the new (but yet to be released) "static" setting to further expand on the behavior of useSingleRequestParameter.

I have realize this behavior with mustache configuration rather than lombok to make it easier to make the behavior even more similar to that of POJOs in the future (e.g., sort parameters so required ones are highlighed in some sense, adding nullable annotations to class fields to highlight/trigger runtime errors when they are required). A single lombok annotation is used to provide equals to the class, to facilitate easier testing when working with mocks and verifying them. I will investigate how to add an equals implementation as a separate issue.

The current implementation for useSingleRequestParameter uses a record for RestClient, and a class for WebClient. In order to bring these SpringClients closer to each other, I have made it so that the RestClient will switch to also using a class when "static" is provided (but retain a record for "true" as to not make a breaking change).

A better description than ..., but also makes the generated arguments class static with single parameter instantiation can probably be made.

cc @bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08)

Edit notes: clarified that I will omit the equals implementation and instead do it separately so I can have time to investigate how to properly express it with mustache syntax.

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 || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (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 Feb 18, 2025

thanks for the PR

also cc @cchacin

@wing328
Copy link
Member

wing328 commented Feb 18, 2025

@Mattias-Sehlstedt can you please review the CI failure when you've time?

@@ -229,6 +228,21 @@ public FakeHttpSignatureTestRequest header1(String header1) {
return this;
}

@Override
public boolean equals(Object o) {
Copy link
Author

@Mattias-Sehlstedt Mattias-Sehlstedt Feb 18, 2025

Choose a reason for hiding this comment

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

Just copying the pojo implementation obviously doesn't get the job done properly. Will investigate if I am able to adjust it or if I will drop equals/hashcode entirely.

I assume the change is to replace Vars with Params in the mustache. But I am not sure what extension settings that would be relevant.

@cchacin
Copy link
Contributor

cchacin commented Feb 20, 2025

LGTM 👍

Copy link
Contributor

@martin-mfg martin-mfg left a comment

Choose a reason for hiding this comment

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

With both webclient and restclient, when using the new option useSingleRequestParameter=static the generated code doesn't compile. Please fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REQ] [java] [client] one-by-one parameter instantiation for SingleRequestParameter model
4 participants