Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.SimpleAssociationHandler;
import org.springframework.data.mapping.context.PersistentEntities;
import org.springframework.data.rest.core.annotation.RestResource;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.core.mapping.ResourceMappings;
import org.springframework.data.rest.core.mapping.ResourceMetadata;
Expand Down Expand Up @@ -133,7 +134,7 @@ public void customise(OpenAPI openAPI, ResourceMappings mappings, PersistentEnti
entityInfo.setAssociationsFields(associationsFields);
entityInoMap.put(domainType.getSimpleName(), entityInfo);
}

openAPI.getPaths().entrySet().stream()
.forEach(stringPathItemEntry -> {
PathItem pathItem = stringPathItemEntry.getValue();
Expand Down Expand Up @@ -417,9 +418,11 @@ private List<String> getAssociationsFields(ResourceMetadata
List<String> associationsFields = new ArrayList<>();
entity.doWithAssociations((SimpleAssociationHandler) association -> {
PersistentProperty<?> property = association.getInverse();
String filedName = resourceMetadata.getMappingFor(property).getRel().value();
associationsFields.add(filedName);
});
if (isAssociationExported(property)) {
String filedName = resourceMetadata.getMappingFor(property).getRel().value();
associationsFields.add(filedName);
}
});
return associationsFields;
}

Expand All @@ -438,13 +441,31 @@ private List<String> getIgnoredFields(ResourceMetadata
ignoredFields.add(idField);
entity.doWithAssociations((SimpleAssociationHandler) association -> {
PersistentProperty<?> property = association.getInverse();
String filedName = resourceMetadata.getMappingFor(property).getRel().value();
ignoredFields.add(filedName);
});
if (isAssociationExported(property)) {
String filedName = resourceMetadata.getMappingFor(property).getRel().value();
ignoredFields.add(filedName);
}
});
}
return ignoredFields;
}

/**
* Indicates if an association is exported. If not, it should be included in response schema.
*
* @param associationProperty the property to check
* @return true if a field is not exported
*/
private boolean isAssociationExported(PersistentProperty<?> associationProperty) {
try {
RestResource restResource = associationProperty.getRequiredAnnotation(RestResource.class);
return restResource.exported();
} catch (IllegalStateException e) {
//if annotation missing, association is exported by default
return true;
}
}

/**
* Build text uri content.
*
Expand Down