Skip to content

Commit

Permalink
Fix #257 Frame aliasing @graph with omitGraph=true
Browse files Browse the repository at this point in the history
  • Loading branch information
lolgab committed Nov 17, 2023
1 parent 22498ab commit 91222d5
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@ public static final JsonObject frame(final Document input, final Document frame,
.newContext()
.create(context, contextBase);

final String graphKey = activeContext.uriCompaction().vocab(true).compact(Keywords.GRAPH);

// 13.
boolean frameDefault = false;
for (final String key : frameObject.keySet()) {
if(activeContext.uriExpansion().vocab(true).expand(key).equals(Keywords.GRAPH)) {
if(key.equals(graphKey)) {
frameDefault = true;
break;
}
Expand Down Expand Up @@ -209,10 +211,8 @@ public static final JsonObject frame(final Document input, final Document frame,
// 19.2.
} else if (JsonUtils.isArray(compactedResults)) {

final String key = activeContext.uriCompaction().vocab(true).compact(Keywords.GRAPH);

compactedResults = JsonProvider.instance().createObjectBuilder()
.add(key, compactedResults).build();
.add(graphKey, compactedResults).build();

}

Expand All @@ -230,17 +230,16 @@ public static final JsonObject frame(final Document input, final Document frame,
}

// 21.
if (!omitGraph && !compactedResults.asJsonObject().containsKey(Keywords.GRAPH)) {

if (!omitGraph && !compactedResults.asJsonObject().containsKey(graphKey)) {
if (compactedResults.asJsonObject().isEmpty()) {

compactedResults = JsonProvider.instance().createObjectBuilder().add(Keywords.GRAPH,
compactedResults = JsonProvider.instance().createObjectBuilder().add(graphKey,
JsonValue.EMPTY_JSON_ARRAY
).build();

} else {

compactedResults = JsonProvider.instance().createObjectBuilder().add(Keywords.GRAPH,
compactedResults = JsonProvider.instance().createObjectBuilder().add(graphKey,
JsonProvider.instance().createArrayBuilder().add(compactedResults)
).build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"@context": {
"data": "@graph"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"@id": "http://example.org/foo",
"http://example.org/name": "Foo"
}
11 changes: 11 additions & 0 deletions src/test/resources/com/apicatalog/jsonld/test/issue257-2-out.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"@context": {
"data": "@graph"
},
"data": [
{
"@id": "http://example.org/foo",
"http://example.org/name": "Foo"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"@context": {
"data": "@graph"
}
}
12 changes: 12 additions & 0 deletions src/test/resources/com/apicatalog/jsonld/test/issue257-in.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"@graph": [
{
"@id": "http://example.org/foo",
"http://example.org/name": "Foo"
},
{
"@id": "http://example.org/bar",
"http://example.org/name": "Bar"
}
]
}
15 changes: 15 additions & 0 deletions src/test/resources/com/apicatalog/jsonld/test/issue257-out.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"@context": {
"data": "@graph"
},
"data": [
{
"@id": "http://example.org/bar",
"http://example.org/name": "Bar"
},
{
"@id": "http://example.org/foo",
"http://example.org/name": "Foo"
}
]
}
18 changes: 18 additions & 0 deletions src/test/resources/com/apicatalog/jsonld/test/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@
"input": "issue198-in.json",
"expect": "issue198-out.json",
"option": { "expandContext" : "issue198-context.json", "base": "http://leanix.net/" }
},
{
"@id": "#t0015",
"@type": ["jld:PositiveEvaluationTest", "jld:FrameTest"],
"name": "Issue #257: Frame aliasing @graph",
"input": "issue257-in.json",
"expect": "issue257-out.json",
"frame": "issue257-frame.json",
"option": { "omitGraph" : false }
},
{
"@id": "#t0016",
"@type": ["jld:PositiveEvaluationTest", "jld:FrameTest"],
"name": "Issue #257: Frame aliasing @graph compact input",
"input": "issue257-2-in.json",
"expect": "issue257-2-out.json",
"frame": "issue257-2-frame.json",
"option": { "omitGraph" : false }
}
]
}

0 comments on commit 91222d5

Please sign in to comment.