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

[BUG] HandlebarsEngineAdapter.java failed to use custom FieldValueResolver causing IllegalAccessException for maps #19634

Conversation

WouterBaeyens
Copy link
Contributor

@WouterBaeyens WouterBaeyens commented Sep 21, 2024

The old MY_FIELD_VALUE_RESOLVER.INSTANCE is equivalent to FieldValueResolver.INSTANCE, which is assigned new FieldValueResolver(); so our custom class was never used.

This should improve #510 somewhat, and finally properly applies the suggestion from jknack/handlebars.java#940 (comment)

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.

The old MY_FIELD_VALUE_RESOLVER.INSTANCE is equivalent to FieldValueResolver.INSTANCE, which is assigned `new FieldValueResolver();` so our custom class was never used.
@WouterBaeyens WouterBaeyens force-pushed the 510-handlebars-wrong-fieldresolver-instance branch 3 times, most recently from e1eafee to 5098455 Compare September 26, 2024 19:44
@WouterBaeyens
Copy link
Contributor Author

I added the test and did a little bit of clean-up as well.

  • I have split off AccessAwareFieldValueResolver
    • It keeps the format aligned with the usage of the INSTANCE singleton
    • It enables us in test-methods like HandlebarsEngineAdapterTest to test using the resolver actually active in the code.
  • I re-ordered the MethodValueResolver to take priority.
    • This is what was suggested by the maintainers of the handlebars repo
    • Map, JavaBean, Method, Value order makes more sense. i.e. getKey() > key() > key especially after the introduction of records is more logical over getKey() > key > key().

@wing328 let me know if you feel the tests are insufficient or further discussion is warranted. I realize I've slightly increased the scope of my change, but with increased understanding I've become pretty confident on the logical order of the resolvers.

@WouterBaeyens WouterBaeyens force-pushed the 510-handlebars-wrong-fieldresolver-instance branch from 5098455 to 605345d Compare September 26, 2024 20:03
…lueResolver; Add test verifying priority fo values extracted from object
@WouterBaeyens WouterBaeyens force-pushed the 510-handlebars-wrong-fieldresolver-instance branch from 605345d to 998cdeb Compare September 26, 2024 20:16
@WouterBaeyens
Copy link
Contributor Author

ping @wing328
Are the changes too complex to review with limited time-resources?
If you want I can revert the subsequent changes and create a follow-up mr for those.
I would like to help make handlebars a viable alternative and fixing partial templates is I think a requirement to do this.

Maybe there are people specific to handlebars I could tag instead?

@wing328
Copy link
Member

wing328 commented Oct 3, 2024

thanks for the PR. let's give it a try

@wing328 wing328 merged commit 6686c4d into OpenAPITools:master Oct 3, 2024
15 checks passed
@WouterBaeyens WouterBaeyens deleted the 510-handlebars-wrong-fieldresolver-instance branch October 4, 2024 18:51
@wing328 wing328 added this to the 7.9.0 milestone Oct 7, 2024
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.

2 participants