Skip to content

Commit 3d7458b

Browse files
committed
#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.
1 parent ab02d45 commit 3d7458b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/main/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsTemplateBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public Map<String, HalFormsTemplate> findTemplates(RepresentationModel<?> resour
7070
.withProperties(factory.createProperties(it))
7171
.withContentType(it.getInput().getPrimaryMediaType());
7272

73-
String target = it.getLink().getHref();
73+
String target = it.getLink().expand().getHref();
7474

7575
if (selfLink == null || !target.equals(selfLink.getHref())) {
7676
template = template.withTarget(target);

src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsTemplateBuilderUnitTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,22 @@ void exposesHttpMethodInAllCaps() {
230230
assertThat(HalFormsTemplate.forMethod(HttpMethod.POST).getMethod()).isEqualTo("POST");
231231
}
232232

233+
@Test
234+
void expandsAffordanceLinkForFormTarget() {
235+
236+
HalFormsConfiguration configuration = new HalFormsConfiguration();
237+
238+
RepresentationModel<?> models = new RepresentationModel<>(
239+
Affordances.of(Link.of("/example{?foo}", LinkRelation.of("example"))) //
240+
.afford(HttpMethod.POST) //
241+
.toLink());
242+
243+
Map<String, HalFormsTemplate> templates = new HalFormsTemplateBuilder(configuration, MessageResolver.DEFAULTS_ONLY)
244+
.findTemplates(models);
245+
246+
assertThat(templates.get("default").getTarget()).endsWith("/example");
247+
}
248+
233249
@Getter
234250
static class PatternExample extends RepresentationModel<PatternExample> {
235251

0 commit comments

Comments
 (0)