@@ -539,12 +539,11 @@ auto SchemaFrame::analyse(const JSON &root, const SchemaWalker &walker,
539539 entry.parent = path.concat (relative_entry.parent .value ());
540540 }
541541
542- // Dialect
542+ // Dialect and Base dialect
543543 assert (entry.dialect .has_value ());
544- base_dialects.insert ({entry.pointer , {entry.dialect .value ()}});
545-
546- // Base dialect
547544 assert (entry.base_dialect .has_value ());
545+ base_dialects.insert (
546+ {entry.pointer , {entry.dialect .value (), entry.base_dialect .value ()}});
548547
549548 // Schema identifier
550549 std::optional<JSON::String> id{sourcemeta::core::identify (
@@ -651,6 +650,21 @@ auto SchemaFrame::analyse(const JSON &root, const SchemaWalker &walker,
651650 }
652651 }
653652 }
653+ } else if (!entry.id .has_value () &&
654+ entry.common .subschema .get ().is_object () &&
655+ entry.common .subschema .get ().defines (" $schema" ) &&
656+ ref_overrides_adjacent_keywords (
657+ entry.common .base_dialect .value ())) {
658+ // Handle $schema without $id in Draft 7 and older
659+ // Already inserted into base_dialects with both dialect and
660+ // base_dialect above Just need to insert into base_uris with parent's
661+ // base URI
662+ const auto bases{
663+ find_nearest_bases (base_uris, entry.common .pointer , std::nullopt )};
664+ if (!bases.first .empty ()) {
665+ const auto &parent_base{bases.first .front ()};
666+ base_uris.insert ({entry.common .pointer , {parent_base}});
667+ }
654668 }
655669
656670 if (this ->mode_ != SchemaFrame::Mode::Locations) {
@@ -800,7 +814,7 @@ auto SchemaFrame::analyse(const JSON &root, const SchemaWalker &walker,
800814
801815 const auto dialects{
802816 find_nearest_bases (base_dialects, pointer, root_dialect)};
803- assert (dialects.first .size () = = 1 );
817+ assert (dialects.first .size () > = 1 );
804818
805819 auto every_base_result = find_every_base (base_uris, pointer);
806820
@@ -826,10 +840,15 @@ auto SchemaFrame::analyse(const JSON &root, const SchemaWalker &walker,
826840 const auto maybe_base_entry{this ->locations_ .find (
827841 {SchemaReferenceType::Static, current_base})};
828842
843+ // Look up base_dialect from base_dialects (second element if present)
844+ const auto base_dialect_result{
845+ find_nearest_bases (base_dialects, pointer, root_dialect)};
829846 const auto current_base_dialect{
830- maybe_base_entry == this ->locations_ .cend ()
831- ? root_base_dialect.value ()
832- : maybe_base_entry->second .base_dialect };
847+ base_dialect_result.first .size () >= 2
848+ ? base_dialect_result.first [1 ]
849+ : (maybe_base_entry == this ->locations_ .cend ()
850+ ? root_base_dialect.value ()
851+ : maybe_base_entry->second .base_dialect )};
833852
834853 const auto subschema{subschemas.find (pointer)};
835854
0 commit comments