Given a resource named main having two related resources of type a and b.
When requesting main using fields[a]=label and fields[b]=labelResult all fields of resource b are returned.
Expected only label must be returned.
Example :
Resources
@JsonApiResource(type = "main")
public class MainResource {
@JsonApiId
private String id;
@JsonApiRelation
private RelatedResourceA relatedResourceA;
@JsonApiRelation
private RelatedResourceB relatedResourceB;
}
@JsonApiResource(type = "a")
public class RelatedResourceA {
@JsonApiId
private String id;
private String label;
private String otherField;
}
@JsonApiResource(type = "b")
public class RelatedResourceB {
@JsonApiId
private String id;
private String label;
private String somethingDifferent;
}
NB: Getters and setters are omitted for brevity.
Requests
NB: requests are written with httpie, for these examples, you just have to know that 'x==y' means add a request parameter x with value y.
public Collection<QuerySpec> getNestedSpecs() {
// Using a set to remove duplicate querySpec between typeRelatedSpecs and classRelatedSpecs
Set<QuerySpec> allRelatedSpecs = new HashSet(typeRelatedSpecs.values());
allRelatedSpecs.addAll(classRelatedSpecs.values());
return Collections.unmodifiableCollection(allRelatedSpecs);
}
and
QuerySpec.equals does not use resourceType (neither resourceClass).
So when DocumentMapperUtil.getRequestedFields is called, QuerySpecAdapter.getIncludedFields is called, and then QuerySpec.getNestedSpecs is called ... and a spec is missing.
Issue
Given a resource named
main
having two related resources of typea
andb
. When requestingmain
usingfields[a]=label
andfields[b]=label
Result all fields of resourceb
are returned. Expected onlylabel
must be returned.Example :
Resources
NB: Getters and setters are omitted for brevity.
Requests
NB: requests are written with httpie, for these examples, you just have to know that 'x==y' means add a request parameter x with value y.
No fields :+1:
http :8080/main/mainId include==relatedResourceA,relatedResourceB
All fields from resource A and resource B are returned.
Only label for resource A (or resource B) :+1:
http :8080/main/mainId include==relatedResourceA,relatedResourceB 'fields[a]==label'
Field
otherField
has been filtered out.Only label for resource A and resource B :-1:
http :8080/main/mainId include==relatedResourceA,relatedResourceB 'fields[a]==label' 'fields[b]==label'
The field 'somethingDifferent' is returned when it shouldn't
Here the full spring boot app to illustrate You need maven and java (8+), unzip, go to directory, run
mvn spring-boot:run
Causes :
QuerySpec. getNestedSpecs returns a Set of QuerySpec
and
QuerySpec.equals does not use resourceType (neither resourceClass).
So when DocumentMapperUtil.getRequestedFields is called, QuerySpecAdapter.getIncludedFields is called, and then QuerySpec.getNestedSpecs is called ... and a spec is missing.