-
Notifications
You must be signed in to change notification settings - Fork 472
Open
Labels
Description
We'd like to add custom attributes to HalFormsProperty
. This seems allowed by HAL-FORMS specification but it seems currently impossible with Spring HATEAOS.
IMO, the best extension point would be somewhere here:
Lines 83 to 108 in 3a9d0ba
return model.createProperties((payload, metadata) -> { | |
String inputType = metadata.getInputType(); | |
HalFormsOptions options = optionsFactory.getOptions(payload, metadata); | |
HalFormsProperty property = new HalFormsProperty() | |
.withName(metadata.getName()) | |
.withRequired(metadata.isRequired()) // | |
.withReadOnly(metadata.isReadOnly()) | |
.withMin(metadata.getMin()) | |
.withMax(metadata.getMax()) | |
.withMinLength(metadata.getMinLength()) | |
.withMaxLength(metadata.getMaxLength()) | |
.withRegex(lookupRegex(metadata)) // | |
.withType(inputType) // | |
.withValue(options != null ? options.getSelectedValue() : null) // | |
.withOptions(options); | |
Function<String, I18nedPropertyMetadata> factory = I18nedPropertyMetadata.factory(payload, property); | |
return Optional.of(property) | |
.map(it -> i18n(it, factory.apply("_placeholder"), it::withPlaceholder)) | |
.map(it -> i18n(it, factory.apply("_prompt"), it::withPrompt)) | |
.map(it -> model.hasHttpMethod(HttpMethod.PATCH) ? it.withRequired(false) : it) | |
.orElse(property); | |
}); |
I guess that would mean adding a free Map to HalFormsProperty
and a PropertyCustomizer
SPI looking like this:
interface PropertyCustomizer {
HalFormsProperty customize(HalFormsProperty property, InputPayloadMetadata payload, PropertyMetadata metadata, PropertyCreationContext context);
}