DATAREST-690 - Fixed JSON schema handling for collection associations.

We now make sure not to render an items nor an uniqueItems clause for collection associations as they are exposed as URIs for which JSON schema doesn't allow these attributes.
This commit is contained in:
Oliver Gierke
2015-11-09 08:36:14 +01:00
parent 3a6b9ea3ff
commit bb612e0ea0
3 changed files with 18 additions and 1 deletions

View File

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

View File

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

View File

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