1+ #include < sourcemeta/blaze/alterschema.h>
12#include < sourcemeta/codegen/ir.h>
2- #include < sourcemeta/core/alterschema.h>
33
44#include < algorithm> // std::ranges::sort
55#include < cassert> // assert
99
1010namespace sourcemeta ::codegen {
1111
12+ static auto
13+ is_validation_only_location (const sourcemeta::core::WeakPointer &pointer)
14+ -> bool {
15+ static const std::unordered_set<std::string_view> validation_only_keywords{
16+ " propertyNames" , " contains" };
17+ static const std::unordered_set<std::string_view> container_keywords{
18+ " properties" , " patternProperties" , " $defs" , " definitions" };
19+ for (std::size_t index = 0 ; index < pointer.size (); ++index) {
20+ const auto &token{pointer.at (index)};
21+ if (!token.is_property () ||
22+ !validation_only_keywords.contains (token.to_property ())) {
23+ continue ;
24+ }
25+
26+ if (index == 0 || !pointer.at (index - 1 ).is_property () ||
27+ !container_keywords.contains (pointer.at (index - 1 ).to_property ())) {
28+ return true ;
29+ }
30+ }
31+
32+ return false ;
33+ }
34+
1235auto compile (const sourcemeta::core::JSON &input,
1336 const sourcemeta::core::SchemaWalker &walker,
1437 const sourcemeta::core::SchemaResolver &resolver,
@@ -25,9 +48,9 @@ auto compile(const sourcemeta::core::JSON &input,
2548 // (2) Canonicalize the schema for easier analysis
2649 // --------------------------------------------------------------------------
2750
28- sourcemeta::core ::SchemaTransformer canonicalizer;
29- sourcemeta::core ::add (canonicalizer,
30- sourcemeta::core ::AlterSchemaMode::Canonicalizer);
51+ sourcemeta::blaze ::SchemaTransformer canonicalizer;
52+ sourcemeta::blaze ::add (canonicalizer,
53+ sourcemeta::blaze ::AlterSchemaMode::Canonicalizer);
3154 [[maybe_unused]] const auto canonicalized{canonicalizer.apply (
3255 schema, walker, resolver,
3356 [](const auto &, const auto , const auto , const auto &,
@@ -67,6 +90,12 @@ auto compile(const sourcemeta::core::JSON &input,
6790 continue ;
6891 }
6992
93+ // Skip subschemas under validation-only keywords that do not contribute
94+ // to the type structure
95+ if (is_validation_only_location (location.pointer )) {
96+ continue ;
97+ }
98+
7099 const auto &subschema{sourcemeta::core::get (schema, location.pointer )};
71100 result.push_back (compiler (schema, frame, location, resolver, subschema));
72101 }
0 commit comments