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

HOCON properties rendered incorrectly #1225

Open
kdubb opened this issue Sep 20, 2024 · 4 comments
Open

HOCON properties rendered incorrectly #1225

kdubb opened this issue Sep 20, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@kdubb
Copy link

kdubb commented Sep 20, 2024

In HOCON, it's Path.render quotes anything it doesn't like, including things like % for profiles, [] for lists/arrays and / used in projects like SmallRye FaultTolerance.

Basically it produces a lot of quoted sections to the properties it produces that make them incorrect. Some examples:

  • Percent
    %dev.some.property becomes "%dev".some.property
  • Forward Slashes
    org.acme.CoffeeResource/coffees/Retry/maxRetries=6 becomes org.acme."CoffeeResource/coffees/Retry/maxRetries"=6
  • Brackets (which aren't usually necessary)
    my.indexed.collection[0]=dog becomes my.indexed."collection[0]"=dog

There doesn't seem to be a way, currently, to represent these properties in HOCON files.

@kdubb
Copy link
Author

kdubb commented Sep 21, 2024

I wrote an internal version of the module to quickly fix these issues for us. The solution is fairly simple with a few caveats because there is seemingly no way to "render" a key path in code consuming a config from the library; it always renders them itself before returning them.

So the fix looks like this:

  1. Generate flattened keys as is currently done.
  2. Use the ConfigImplUtil.parsePath to retrieve the path from flattened keys.
    a. Requires generating indexed paths with the [0] part quoted to be a valid HOCON path.
  3. Rebuild the path in a representation compliant with SmallRye Config.
    a. Quote any empty path elements or those having matches in [.\s\"]
    b. Join the elements using '.'

If I find the time I can look at making a PR for this but I'm pretty swamped at the moment.

@radcortez
Copy link
Member

Thank you for the report.

I was considering deprecating and removing the HOCON source due to:

We have no plans to invest effort in an abandoned library unless it is super popular, which is not the case. For the time being, we do accept any PRs that improve the implementation, of course.

Would you consider moving away from the HOCON source?

@radcortez radcortez added the bug Something isn't working label Sep 23, 2024
@kdubb
Copy link
Author

kdubb commented Sep 24, 2024

I've read those as we use HOCON. As the previous maintainer has said a few times, the library works with a few known issues but no real showstoppers. All in all, it's much better than YAML for config (in practice YAML trades repetition for lots of unnecessary indentations).

That being considered, I would say that if SmallRye Config's YAML support included breaking keys with dots in them into key "paths"... we'd switch to that in a hearbeat. That's really "the thing" that makes HOCON better.

So a YAML format that treated:

this.is.a.key.path: the-value

as if it were

this:
  is:
   a:
    key:
     path: the-value

I would see no value in HOCON.

@kdubb
Copy link
Author

kdubb commented Sep 24, 2024

Not sure what SR Config is usign for YAML parsing but I know that being able to detect/specify quoated vs. unquoted keys is usually available (unless your using a meta-library like Jackson). So the above could be implemented and allow leaving quoted (single or double) keys alone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants