#1697 - Support for custom property types in HAL FORMS.
As per the discussion in mamund/hal-forms#88, the list of property types in HAL FORMS is not exhaustive. This means we cannot align them with HTML input types and even more so not drop anything not an HTML input type. This is now implemented by switching to generic Strings in the HAL FORMS property DTO and directly piping the value originally registered on the affordance into it.
This commit is contained in:
@@ -37,6 +37,7 @@ import org.hibernate.validator.constraints.Range;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.springframework.hateoas.InputType;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
@@ -246,6 +247,23 @@ class HalFormsTemplateBuilderUnitTest {
|
||||
assertThat(templates.get("default").getTarget()).endsWith("/example");
|
||||
}
|
||||
|
||||
@Test // #1697
|
||||
void exposesCustomInputType() {
|
||||
|
||||
RepresentationModel<?> models = new RepresentationModel<>(
|
||||
Affordances.of(Link.of("/example", LinkRelation.of("example"))) //
|
||||
.afford(HttpMethod.POST) //
|
||||
.withInput(WithCustomInputType.class) //
|
||||
.toLink());
|
||||
|
||||
Map<String, HalFormsTemplate> templates = new HalFormsTemplateBuilder(new HalFormsConfiguration(),
|
||||
MessageResolver.DEFAULTS_ONLY).findTemplates(models);
|
||||
|
||||
assertThat(templates.get("default").getPropertyByName("property")).hasValueSatisfying(it -> {
|
||||
assertThat(it.getType()).isEqualTo("custom");
|
||||
});
|
||||
}
|
||||
|
||||
@Getter
|
||||
static class PatternExample extends RepresentationModel<PatternExample> {
|
||||
|
||||
@@ -283,4 +301,11 @@ class HalFormsTemplateBuilderUnitTest {
|
||||
@DecimalMax("5.3") //
|
||||
BigDecimal decimal;
|
||||
}
|
||||
|
||||
@Getter
|
||||
static class WithCustomInputType {
|
||||
|
||||
@InputType("custom") //
|
||||
String property;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user