#1662 - HAL FORMS template target must be a URL.
We now expand the affordance link before we add it to the HAL FORMS template. Also see #1660.
This commit is contained in:
@@ -70,7 +70,7 @@ class HalFormsTemplateBuilder {
|
||||
.withProperties(factory.createProperties(it))
|
||||
.withContentType(it.getInput().getPrimaryMediaType());
|
||||
|
||||
String target = it.getLink().getHref();
|
||||
String target = it.getLink().expand().getHref();
|
||||
|
||||
if (selfLink == null || !target.equals(selfLink.getHref())) {
|
||||
template = template.withTarget(target);
|
||||
|
||||
@@ -230,6 +230,22 @@ class HalFormsTemplateBuilderUnitTest {
|
||||
assertThat(HalFormsTemplate.forMethod(HttpMethod.POST).getMethod()).isEqualTo("POST");
|
||||
}
|
||||
|
||||
@Test
|
||||
void expandsAffordanceLinkForFormTarget() {
|
||||
|
||||
HalFormsConfiguration configuration = new HalFormsConfiguration();
|
||||
|
||||
RepresentationModel<?> models = new RepresentationModel<>(
|
||||
Affordances.of(Link.of("/example{?foo}", LinkRelation.of("example"))) //
|
||||
.afford(HttpMethod.POST) //
|
||||
.toLink());
|
||||
|
||||
Map<String, HalFormsTemplate> templates = new HalFormsTemplateBuilder(configuration, MessageResolver.DEFAULTS_ONLY)
|
||||
.findTemplates(models);
|
||||
|
||||
assertThat(templates.get("default").getTarget()).endsWith("/example");
|
||||
}
|
||||
|
||||
@Getter
|
||||
static class PatternExample extends RepresentationModel<PatternExample> {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user