Skip to content

Commit 5d59e9e

Browse files
committed
Extend frame entries to record base dialects
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 4db0ded commit 5d59e9e

13 files changed

+490
-166
lines changed

src/jsonschema/frame.cc

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static auto store(sourcemeta::jsontoolkit::FrameLocations &frame,
9999
const std::string &base_id,
100100
const sourcemeta::jsontoolkit::Pointer &pointer_from_root,
101101
const sourcemeta::jsontoolkit::Pointer &pointer_from_base,
102-
const std::string &dialect,
102+
const std::string &dialect, const std::string &base_dialect,
103103
const bool ignore_if_present = false) -> void {
104104
const auto canonical{
105105
sourcemeta::jsontoolkit::URI{uri}.canonicalize().recompose()};
@@ -111,6 +111,7 @@ static auto store(sourcemeta::jsontoolkit::FrameLocations &frame,
111111
pointer_from_root,
112112
pointer_from_base,
113113
dialect,
114+
base_dialect,
114115
{}}})
115116
.second};
116117
if (!ignore_if_present && !inserted) {
@@ -165,7 +166,8 @@ auto sourcemeta::jsontoolkit::frame(
165166
store(frame, ReferenceType::Static, FrameLocationType::Resource,
166167
default_id.value(), root_id.value(), root_id.value(),
167168
sourcemeta::jsontoolkit::empty_pointer,
168-
sourcemeta::jsontoolkit::empty_pointer, root_dialect.value());
169+
sourcemeta::jsontoolkit::empty_pointer, root_dialect.value(),
170+
root_base_dialect.value());
169171
base_uris.insert(
170172
{sourcemeta::jsontoolkit::empty_pointer, {default_id.value()}});
171173
}
@@ -224,10 +226,12 @@ auto sourcemeta::jsontoolkit::frame(
224226

225227
if (!maybe_relative_is_absolute ||
226228
!frame.contains({ReferenceType::Static, new_id})) {
229+
assert(entry.common.base_dialect.has_value());
227230
store(frame, ReferenceType::Static, FrameLocationType::Resource,
228231
new_id, root_id, new_id, entry.common.pointer,
229232
sourcemeta::jsontoolkit::empty_pointer,
230-
entry.common.dialect.value());
233+
entry.common.dialect.value(),
234+
entry.common.base_dialect.value());
231235
}
232236

233237
if (base_uris.contains(entry.common.pointer)) {
@@ -275,23 +279,26 @@ auto sourcemeta::jsontoolkit::frame(
275279
store(frame, ReferenceType::Static, FrameLocationType::Anchor,
276280
relative_anchor_uri, root_id, "", entry.common.pointer,
277281
entry.common.pointer.resolve_from(bases.second),
278-
entry.common.dialect.value());
282+
entry.common.dialect.value(),
283+
entry.common.base_dialect.value());
279284
}
280285

281286
if (type == sourcemeta::jsontoolkit::AnchorType::Dynamic ||
282287
type == sourcemeta::jsontoolkit::AnchorType::All) {
283288
store(frame, ReferenceType::Dynamic, FrameLocationType::Anchor,
284289
relative_anchor_uri, root_id, "", entry.common.pointer,
285290
entry.common.pointer.resolve_from(bases.second),
286-
entry.common.dialect.value());
291+
entry.common.dialect.value(),
292+
entry.common.base_dialect.value());
287293

288294
// Register a dynamic anchor as a static anchor if possible too
289295
if (entry.common.vocabularies.contains(
290296
"https://json-schema.org/draft/2020-12/vocab/core")) {
291297
store(frame, ReferenceType::Static, FrameLocationType::Anchor,
292298
relative_anchor_uri, root_id, "", entry.common.pointer,
293299
entry.common.pointer.resolve_from(bases.second),
294-
entry.common.dialect.value(), true);
300+
entry.common.dialect.value(),
301+
entry.common.base_dialect.value(), true);
295302
}
296303
}
297304
} else {
@@ -321,7 +328,8 @@ auto sourcemeta::jsontoolkit::frame(
321328
FrameLocationType::Anchor, anchor_uri, root_id, base_string,
322329
entry.common.pointer,
323330
entry.common.pointer.resolve_from(bases.second),
324-
entry.common.dialect.value());
331+
entry.common.dialect.value(),
332+
entry.common.base_dialect.value());
325333
}
326334

327335
if (type == sourcemeta::jsontoolkit::AnchorType::Dynamic ||
@@ -330,7 +338,8 @@ auto sourcemeta::jsontoolkit::frame(
330338
FrameLocationType::Anchor, anchor_uri, root_id, base_string,
331339
entry.common.pointer,
332340
entry.common.pointer.resolve_from(bases.second),
333-
entry.common.dialect.value());
341+
entry.common.dialect.value(),
342+
entry.common.base_dialect.value());
334343

335344
// Register a dynamic anchor as a static anchor if possible too
336345
if (entry.common.vocabularies.contains(
@@ -339,7 +348,8 @@ auto sourcemeta::jsontoolkit::frame(
339348
FrameLocationType::Anchor, anchor_uri, root_id, base_string,
340349
entry.common.pointer,
341350
entry.common.pointer.resolve_from(bases.second),
342-
entry.common.dialect.value(), true);
351+
entry.common.dialect.value(),
352+
entry.common.base_dialect.value(), true);
343353
}
344354
}
345355

@@ -377,16 +387,26 @@ auto sourcemeta::jsontoolkit::frame(
377387
const auto nearest_bases{
378388
find_nearest_bases(base_uris, pointer, base.first)};
379389
assert(!nearest_bases.first.empty());
390+
const auto &current_base{nearest_bases.first.front()};
380391
if (subschemas.contains(pointer)) {
392+
auto current_base_dialect{
393+
base_dialect(get(schema, pointer), resolver, root_dialect)};
394+
assert(current_base_dialect.has_value());
381395
store(frame, ReferenceType::Static, FrameLocationType::Subschema,
382-
result, root_id, nearest_bases.first.front(), pointer,
396+
result, root_id, current_base, pointer,
383397
pointer.resolve_from(nearest_bases.second),
384-
dialects.first.front());
398+
dialects.first.front(), current_base_dialect.value());
399+
} else if (frame.contains({ReferenceType::Static, current_base})) {
400+
store(frame, ReferenceType::Static, FrameLocationType::Pointer,
401+
result, root_id, current_base, pointer,
402+
pointer.resolve_from(nearest_bases.second),
403+
dialects.first.front(),
404+
frame.at({ReferenceType::Static, current_base}).base_dialect);
385405
} else {
386406
store(frame, ReferenceType::Static, FrameLocationType::Pointer,
387-
result, root_id, nearest_bases.first.front(), pointer,
407+
result, root_id, current_base, pointer,
388408
pointer.resolve_from(nearest_bases.second),
389-
dialects.first.front());
409+
dialects.first.front(), "!!!! TODO");
390410
}
391411
}
392412
}

src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_frame.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct FrameLocationsEntry {
6767
Pointer pointer;
6868
Pointer relative_pointer;
6969
std::string dialect;
70+
std::string base_dialect;
7071
std::vector<std::reference_wrapper<const FrameReferences::key_type>>
7172
destination_of;
7273
};

0 commit comments

Comments
 (0)