spring-projects / spring-projects/spring-hateoas

`HalFormsConfiguration#withOptions` is based on a property name depending on an non obvious internal algorithm

Open
#2,040 2 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Nov 13, 2023.

process: waiting for feedback
Dominant language
Java
Stars
1.1k
Forks
476
PR merge metrics
No merged PRs in 30d

Description

I'd like to customize HalFormsConfiguration in order to be able to produce HAL-Forms options for some template payload properties via a home made annotation based engine.

My goal is to have something like this:

record Payload(@HalFormsPropertyMetadata(optionsFactory = MyOptionsFactory.class) String foo) {

}

class MyOptionsFactory implements OptionsFactory {
  @Override
  Optional<HalFormsOptions> createOptions(AffordanceModel.PropertyMetadata property) {
    return Optional.empty();
  }
}

public interface OptionsFactory {
  Optional<HalFormsOptions> createOptions(AffordanceModel.PropertyMetadata property);
}

To do that, I need to invoke https://github.com/spring-projects/spring-hateoas/blob/688484610cb9ecf6ee24abae611997fc3b51f0c2/src/main/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsConfiguration.java#L170-L171

The property argument should be the name of the property for which we try to provide options. But this value is computed like this: https://github.com/spring-projects/spring-hateoas/blob/a796509532bf0bb4294eae0573a9839943c36403/src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java#L445-L456
Since this computation is private, I have no other way than copying the Spring HATEOAS name computation code in my project to make sure to match my annotated property with the name expected by Spring HATEOAS.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.