1616
1717namespace {
1818
19- auto is_official_metaschema_reference (
19+ auto is_skippable_metaschema_reference (
20+ const sourcemeta::blaze::BundleMode mode,
2021 const sourcemeta::core::WeakPointer &pointer,
2122 const std::string &destination) -> bool {
2223 assert (!pointer.empty ());
2324 assert (pointer.back ().is_property ());
24- return pointer.back ().to_property () == " $schema" &&
25+ if (pointer.back ().to_property () != " $schema" ) {
26+ return false ;
27+ }
28+
29+ return mode == sourcemeta::blaze::BundleMode::References ||
2530 sourcemeta::blaze::is_official_schema (destination);
2631}
2732
@@ -47,7 +52,9 @@ auto dependencies_internal(
4752 const auto &reference) {
4853 // We don't want to report official schemas, as we can expect
4954 // virtually all implementations to understand them out of the box
50- if (is_official_metaschema_reference (pointer, reference.destination )) {
55+ if (is_skippable_metaschema_reference (
56+ sourcemeta::blaze::BundleMode::NonOfficialMetaschemas, pointer,
57+ reference.destination )) {
5158 return ;
5259 }
5360
@@ -236,6 +243,7 @@ auto bundle_schema(sourcemeta::core::JSON &root,
236243 sourcemeta::core::JSON &subschema,
237244 const sourcemeta::blaze::SchemaWalker &walker,
238245 const sourcemeta::blaze::SchemaResolver &resolver,
246+ const sourcemeta::blaze::BundleMode mode,
239247 std::string_view default_dialect,
240248 std::string_view default_id,
241249 const sourcemeta::blaze::SchemaFrame::Paths &paths,
@@ -265,8 +273,10 @@ auto bundle_schema(sourcemeta::core::JSON &root,
265273 frame.for_each_unresolved_reference ([&](const auto &pointer,
266274 const auto &reference) {
267275 // We don't want to bundle official schemas, as we can expect
268- // virtually all implementations to understand them out of the box
269- if (is_official_metaschema_reference (pointer, reference.destination )) {
276+ // virtually all implementations to understand them out of the box.
277+ // Depending on the bundling strategy, we may skip meta-schemas entirely
278+ if (is_skippable_metaschema_reference (mode, pointer,
279+ reference.destination )) {
270280 return ;
271281 }
272282
@@ -378,8 +388,8 @@ auto bundle_schema(sourcemeta::core::JSON &root,
378388 }
379389
380390 for (auto &[remote, effective_id, remote_dialect] : deferred) {
381- bundle_schema (root, container, remote, walker, resolver, default_dialect ,
382- effective_id, paths, bundled, depth + 1 );
391+ bundle_schema (root, container, remote, walker, resolver, mode ,
392+ default_dialect, effective_id, paths, bundled, depth + 1 );
383393 elevate_embedded_resources (remote, root, container, remote_dialect,
384394 resolver, default_dialect, bundled);
385395 embed_schema (root, container, effective_id, std::move (remote));
@@ -403,8 +413,8 @@ auto dependencies(const sourcemeta::core::JSON &schema,
403413// TODO: Refactor this function to internally rely on the `.dependencies()`
404414// function
405415auto bundle (sourcemeta::core::JSON &schema, const SchemaWalker &walker,
406- const SchemaResolver &resolver, std::string_view default_dialect ,
407- std::string_view default_id,
416+ const SchemaResolver &resolver, const BundleMode mode ,
417+ std::string_view default_dialect, std::string_view default_id,
408418 const std::optional<sourcemeta::core::Pointer> &default_container,
409419 const SchemaFrame::Paths &paths) -> void {
410420 // Pre-scan the schema to find any already-embedded schemas and mark them
@@ -424,7 +434,7 @@ auto bundle(sourcemeta::core::JSON &schema, const SchemaWalker &walker,
424434 // This is undefined behavior
425435 assert (!default_container.value ().empty ());
426436 bundle_schema (schema, default_container.value (), schema, walker, resolver,
427- default_dialect, default_id, paths, bundled);
437+ mode, default_dialect, default_id, paths, bundled);
428438 return ;
429439 }
430440
@@ -477,18 +487,18 @@ auto bundle(sourcemeta::core::JSON &schema, const SchemaWalker &walker,
477487 }
478488
479489 bundle_schema (schema, {sourcemeta::core::JSON ::String{container_keyword}},
480- schema, walker, resolver, default_dialect, default_id, paths ,
481- bundled);
490+ schema, walker, resolver, mode, default_dialect, default_id ,
491+ paths, bundled);
482492}
483493
484494auto bundle (const sourcemeta::core::JSON &schema, const SchemaWalker &walker,
485- const SchemaResolver &resolver, std::string_view default_dialect ,
486- std::string_view default_id,
495+ const SchemaResolver &resolver, const BundleMode mode ,
496+ std::string_view default_dialect, std::string_view default_id,
487497 const std::optional<sourcemeta::core::Pointer> &default_container,
488498 const SchemaFrame::Paths &paths) -> sourcemeta::core::JSON {
489499 sourcemeta::core::JSON copy = schema;
490- bundle (copy, walker, resolver, default_dialect, default_id, default_container ,
491- paths);
500+ bundle (copy, walker, resolver, mode, default_dialect, default_id ,
501+ default_container, paths);
492502 return copy;
493503}
494504
0 commit comments