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:
@@ -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()) {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user