Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #257 Frame aliasing @graph with omitGraph=true #288

Merged
merged 1 commit into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
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 @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this result, please check that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you disable Compact Arrays in JSON-LD Playground you also get a "data" array.
I assumed that Compact Arrays is the equivalent to our omitGraph.
I can add a test case with omitGraph = true if you want

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, good job!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! ❤️

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 }
}
]
}
Loading