diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JsonSchema.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JsonSchema.java index 6bfd0d423..52521855b 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JsonSchema.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JsonSchema.java @@ -420,6 +420,19 @@ public class JsonSchema { return with(STRING_TYPE_INFORMATION); } + /** + * Turns the current {@link JsonSchemaProperty} into an association. + * + * @return + */ + public JsonSchemaProperty asAssociation() { + + this.items = null; + this.uniqueItems = null; + + return withFormat(JsonSchemaFormat.URI); + } + JsonSchemaProperty with(TypeInformation type, String reference) { if (type.isCollectionLike()) { diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverter.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverter.java index f51b7b120..4d02b0d8e 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverter.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverter.java @@ -230,7 +230,7 @@ public class PersistentEntityToJsonSchemaConverter implements ConditionalGeneric } if (associationLinks.isLinkableAssociation(persistentProperty)) { - registrar.register(property.withFormat(JsonSchemaFormat.URI), null); + registrar.register(property.asAssociation(), null); } else { if (persistentProperty.isEntity()) { diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverterUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverterUnitTests.java index 57177e23f..8579a3917 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverterUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverterUnitTests.java @@ -152,6 +152,10 @@ public class PersistentEntityToJsonSchemaConverterUnitTests { constraints.add( new Constraint("$.properties.firstname.title", is("Vorname"), "I18n from property on fully-qualified type")); + // DATAREST-690 + constraints.add(new Constraint("$.properties.colleagues.items", is(nullValue()), + "Items must not appear for collection associations.")); + assertConstraints(User.class, constraints); }