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 a47df0fc7..fd837b7c2 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 @@ -340,7 +340,7 @@ public class JsonSchema { return with(JsonSchemaFormat.DATE_TIME); } - if (type.isCollectionLike()) { + if (type.isCollectionLike() && !JsonSchemaFormat.URI.equals(format)) { if (Set.class.equals(type.getType())) { this.uniqueItems = true; @@ -353,10 +353,19 @@ public class JsonSchema { } Property with(JsonSchemaFormat format) { + this.format = format; return with(STRING_TYPE_INFORMATION); } + Property asAssociation() { + + this.items = null; + this.uniqueItems = null; + + return with(JsonSchemaFormat.URI); + } + Property with(Pattern pattern) { this.pattern = pattern.toString(); return with(STRING_TYPE_INFORMATION); 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 2e014f1ff..dde11702d 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 @@ -162,8 +162,9 @@ public class PersistentEntityToJsonSchemaConverter implements ConditionalGeneric for (BeanPropertyDefinition definition : jackson) { PersistentProperty persistentProperty = entity.getPersistentProperty(definition.getInternalName()); - TypeInformation propertyType = persistentProperty == null ? ClassTypeInformation.from(definition - .getPrimaryMember().getRawType()) : persistentProperty.getTypeInformation(); + TypeInformation propertyType = persistentProperty == null + ? ClassTypeInformation.from(definition.getPrimaryMember().getRawType()) + : persistentProperty.getTypeInformation(); Class rawPropertyType = propertyType.getType(); JsonSchemaFormat format = configuration.metadataConfiguration().getSchemaFormatFor(rawPropertyType); @@ -204,7 +205,7 @@ public class PersistentEntityToJsonSchemaConverter implements ConditionalGeneric } if (associationLinks.isLinkableAssociation(persistentProperty)) { - properties.add(property.with(JsonSchemaFormat.URI)); + properties.add(property.asAssociation()); } else { if (persistentProperty.isEntity()) { @@ -252,8 +253,8 @@ public class PersistentEntityToJsonSchemaConverter implements ConditionalGeneric return new Property(name, resolvedDescription, required); } - return new EnumProperty(name, rawType, description.getDefaultMessage().equals(resolvedDescription) ? null - : resolvedDescription, required); + return new EnumProperty(name, rawType, + description.getDefaultMessage().equals(resolvedDescription) ? null : resolvedDescription, required); } private ResourceDescription getDescriptionFor(PersistentProperty property, ResourceMetadata metadata) { 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 32f1e4497..3aa573e18 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 @@ -139,6 +139,10 @@ public class PersistentEntityToJsonSchemaConverterUnitTests { // DATAREST-531 constraints.add(new Constraint("$.properties.email.readOnly", is(true), "Email is read-only property")); + // DATAREST-690 + constraints.add(new Constraint("$.properties.colleagues.items", is(nullValue()), + "Items must not appear for collection associations.")); + assertConstraints(User.class, constraints); }