#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:
Oliver Drotbohm
2021-10-12 13:52:34 +02:00
parent ab02d45b8e
commit 3d7458b5f6
2 changed files with 17 additions and 1 deletions

View File

@@ -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);

View File

@@ -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> {