Skip to content

Commit 63d593b

Browse files
committed
Revise JSON Schema public interface namespaces
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 3a44f00 commit 63d593b

File tree

52 files changed

+1489
-1430
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1489
-1430
lines changed

src/core/jsonschema/bundle.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ auto is_official_metaschema_reference(const sourcemeta::core::Pointer &pointer,
5353

5454
auto bundle_schema(sourcemeta::core::JSON &root, const std::string &container,
5555
const sourcemeta::core::JSON &subschema,
56-
sourcemeta::core::Frame &frame,
56+
sourcemeta::core::SchemaFrame &frame,
5757
const sourcemeta::core::SchemaWalker &walker,
5858
const sourcemeta::core::SchemaResolver &resolver,
5959
const std::optional<std::string> &default_dialect) -> void {
@@ -137,7 +137,7 @@ auto bundle(sourcemeta::core::JSON &schema, const SchemaWalker &walker,
137137
const std::optional<std::string> &default_dialect) -> void {
138138
const auto vocabularies{
139139
sourcemeta::core::vocabularies(schema, resolver, default_dialect)};
140-
sourcemeta::core::Frame frame;
140+
sourcemeta::core::SchemaFrame frame;
141141
bundle_schema(schema, definitions_keyword(vocabularies), schema, frame,
142142
walker, resolver, default_dialect);
143143
}

src/core/jsonschema/default_walker.cc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ auto sourcemeta::core::default_schema_walker(
55
-> sourcemeta::core::SchemaWalkerResult {
66
#define WALK(vocabulary, _keyword, strategy, ...) \
77
if (vocabularies.contains(vocabulary) && keyword == _keyword) \
8-
return {sourcemeta::core::KeywordType::strategy, vocabulary, {__VA_ARGS__}};
8+
return {sourcemeta::core::SchemaKeywordType::strategy, \
9+
vocabulary, \
10+
{__VA_ARGS__}};
911

1012
#define WALK_ANY(vocabulary_1, vocabulary_2, _keyword, strategy, ...) \
1113
WALK(vocabulary_1, _keyword, strategy, __VA_ARGS__) \
@@ -306,7 +308,8 @@ auto sourcemeta::core::default_schema_walker(
306308
if ((vocabularies.contains(HTTP_BASE "draft-07/schema#") ||
307309
vocabularies.contains(HTTP_BASE "draft-07/hyper-schema#")) &&
308310
keyword != "$ref") {
309-
return {sourcemeta::core::KeywordType::Unknown, std::nullopt, {"$ref"}};
311+
return {
312+
sourcemeta::core::SchemaKeywordType::Unknown, std::nullopt, {"$ref"}};
310313
}
311314

312315
// Draft6
@@ -410,7 +413,8 @@ auto sourcemeta::core::default_schema_walker(
410413
if ((vocabularies.contains(HTTP_BASE "draft-06/schema#") ||
411414
vocabularies.contains(HTTP_BASE "draft-06/hyper-schema#")) &&
412415
keyword != "$ref") {
413-
return {sourcemeta::core::KeywordType::Unknown, std::nullopt, {"$ref"}};
416+
return {
417+
sourcemeta::core::SchemaKeywordType::Unknown, std::nullopt, {"$ref"}};
414418
}
415419

416420
// Draft4
@@ -494,7 +498,8 @@ auto sourcemeta::core::default_schema_walker(
494498
if ((vocabularies.contains(HTTP_BASE "draft-04/schema#") ||
495499
vocabularies.contains(HTTP_BASE "draft-04/hyper-schema#")) &&
496500
keyword != "$ref") {
497-
return {sourcemeta::core::KeywordType::Unknown, std::nullopt, {"$ref"}};
501+
return {
502+
sourcemeta::core::SchemaKeywordType::Unknown, std::nullopt, {"$ref"}};
498503
}
499504

500505
// Draft3
@@ -538,7 +543,8 @@ auto sourcemeta::core::default_schema_walker(
538543
// $ref also takes precedence over any unknown keyword
539544
if (vocabularies.contains(HTTP_BASE "draft-03/schema#") &&
540545
keyword != "$ref") {
541-
return {sourcemeta::core::KeywordType::Unknown, std::nullopt, {"$ref"}};
546+
return {
547+
sourcemeta::core::SchemaKeywordType::Unknown, std::nullopt, {"$ref"}};
542548
}
543549

544550
// Draft2
@@ -662,5 +668,5 @@ auto sourcemeta::core::default_schema_walker(
662668
#undef WALK
663669
#undef WALK_ANY
664670
#undef WALK_MAYBE_DEPENDENT
665-
return {sourcemeta::core::KeywordType::Unknown, std::nullopt, {}};
671+
return {sourcemeta::core::SchemaKeywordType::Unknown, std::nullopt, {}};
666672
}

src/core/jsonschema/frame.cc

Lines changed: 108 additions & 94 deletions
Large diffs are not rendered by default.

src/core/jsonschema/include/sourcemeta/core/jsonschema.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ auto is_schema(const JSON &schema) -> bool;
4949

5050
/// @ingroup jsonschema
5151
/// The strategy to follow when attempting to identify a schema
52-
enum class IdentificationStrategy : std::uint8_t {
52+
enum class SchemaIdentificationStrategy : std::uint8_t {
5353
/// Only proceed if we can guarantee the identifier is valid
5454
Strict,
5555

@@ -83,11 +83,11 @@ enum class IdentificationStrategy : std::uint8_t {
8383
/// guessing game. Often useful if you have a schema without a dialect and you
8484
/// want to at least try to get something.
8585
SOURCEMETA_CORE_JSONSCHEMA_EXPORT
86-
auto identify(
87-
const JSON &schema, const SchemaResolver &resolver,
88-
const IdentificationStrategy strategy = IdentificationStrategy::Strict,
89-
const std::optional<std::string> &default_dialect = std::nullopt,
90-
const std::optional<std::string> &default_id = std::nullopt)
86+
auto identify(const JSON &schema, const SchemaResolver &resolver,
87+
const SchemaIdentificationStrategy strategy =
88+
SchemaIdentificationStrategy::Strict,
89+
const std::optional<std::string> &default_dialect = std::nullopt,
90+
const std::optional<std::string> &default_id = std::nullopt)
9191
-> std::optional<std::string>;
9292

9393
/// @ingroup jsonschema

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,59 +44,59 @@ namespace sourcemeta::core {
4444
/// }
4545
/// })JSON");
4646
///
47-
/// sourcemeta::core::Frame frame;
47+
/// sourcemeta::core::SchemaSchemaFrame frame;
4848
/// frame.analyse(document,
4949
/// sourcemeta::core::default_schema_walker,
5050
/// sourcemeta::core::official_resolver);
5151
///
5252
/// // IDs
53-
/// assert(frame.locations().contains({sourcemeta::core::ReferenceType::Static,
53+
/// assert(frame.locations().contains({sourcemeta::core::SchemaReferenceType::Static,
5454
/// "https://www.example.com/schema"}));
55-
/// assert(frame.locations().contains({sourcemeta::core::ReferenceType::Static,
55+
/// assert(frame.locations().contains({sourcemeta::core::SchemaReferenceType::Static,
5656
/// "https://www.example.com/foo"}));
5757
///
5858
/// // Anchors
59-
/// assert(frame.locations().contains({sourcemeta::core::ReferenceType::Static,
59+
/// assert(frame.locations().contains({sourcemeta::core::SchemaReferenceType::Static,
6060
/// "https://www.example.com/schema#test"}));
6161
///
6262
/// // Root Pointers
63-
/// assert(frame.locations().contains({sourcemeta::core::ReferenceType::Static,
63+
/// assert(frame.locations().contains({sourcemeta::core::SchemaReferenceType::Static,
6464
/// "https://www.example.com/schema#/$id"}));
65-
/// assert(frame.locations().contains({sourcemeta::core::ReferenceType::Static,
65+
/// assert(frame.locations().contains({sourcemeta::core::SchemaReferenceType::Static,
6666
/// "https://www.example.com/schema#/$schema"}));
67-
/// assert(frame.locations().contains({sourcemeta::core::ReferenceType::Static,
67+
/// assert(frame.locations().contains({sourcemeta::core::SchemaReferenceType::Static,
6868
/// "https://www.example.com/schema#/items"}));
69-
/// assert(frame.locations().contains({sourcemeta::core::ReferenceType::Static,
69+
/// assert(frame.locations().contains({sourcemeta::core::SchemaReferenceType::Static,
7070
/// "https://www.example.com/schema#/items/$id"}));
71-
/// assert(frame.locations().contains({sourcemeta::core::ReferenceType::Static,
71+
/// assert(frame.locations().contains({sourcemeta::core::SchemaReferenceType::Static,
7272
/// "https://www.example.com/schema#/items/type"}));
73-
/// assert(frame.locations().contains({sourcemeta::core::ReferenceType::Static,
73+
/// assert(frame.locations().contains({sourcemeta::core::SchemaReferenceType::Static,
7474
/// "https://www.example.com/schema#/properties"}));
75-
/// assert(frame.locations().contains({sourcemeta::core::ReferenceType::Static,
75+
/// assert(frame.locations().contains({sourcemeta::core::SchemaReferenceType::Static,
7676
/// "https://www.example.com/schema#/properties/foo"}));
77-
/// assert(frame.locations().contains({sourcemeta::core::ReferenceType::Static,
77+
/// assert(frame.locations().contains({sourcemeta::core::SchemaReferenceType::Static,
7878
/// "https://www.example.com/schema#/properties/foo/$anchor"}));
79-
/// assert(frame.locations().contains({sourcemeta::core::ReferenceType::Static,
79+
/// assert(frame.locations().contains({sourcemeta::core::SchemaReferenceType::Static,
8080
/// "https://www.example.com/schema#/properties/foo/type"}));
81-
/// assert(frame.locations().contains({sourcemeta::core::ReferenceType::Static,
81+
/// assert(frame.locations().contains({sourcemeta::core::SchemaReferenceType::Static,
8282
/// "https://www.example.com/schema#/properties/bar"}));
83-
/// assert(frame.locations().contains({sourcemeta::core::ReferenceType::Static,
83+
/// assert(frame.locations().contains({sourcemeta::core::SchemaReferenceType::Static,
8484
/// "https://www.example.com/schema#/properties/bar/$ref"}));
8585
///
8686
/// // Subpointers
87-
/// assert(frame.locations().contains({sourcemeta::core::ReferenceType::Static,
87+
/// assert(frame.locations().contains({sourcemeta::core::SchemaReferenceType::Static,
8888
/// "https://www.example.com/foo#/$id"}));
89-
/// assert(frame.locations().contains({sourcemeta::core::ReferenceType::Static,
89+
/// assert(frame.locations().contains({sourcemeta::core::SchemaReferenceType::Static,
9090
/// "https://www.example.com/foo#/type"}));
9191
///
9292
/// // References
93-
/// assert(frame.references().contains({sourcemeta::core::ReferenceType::Static,
93+
/// assert(frame.references().contains({sourcemeta::core::SchemaReferenceType::Static,
9494
/// { "properties", "bar", "$ref" }}));
95-
/// assert(frame.references().at({sourcemeta::core::ReferenceType::Static,
95+
/// assert(frame.references().at({sourcemeta::core::SchemaReferenceType::Static,
9696
/// { "properties", "bar", "$ref" }}).destination ==
9797
/// "https://www.example.com/schema#/properties/foo");
9898
/// ```
99-
class SOURCEMETA_CORE_JSONSCHEMA_EXPORT Frame {
99+
class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaFrame {
100100
public:
101101
/// A single entry in a JSON Schema reference map
102102
struct ReferencesEntry {
@@ -113,7 +113,7 @@ class SOURCEMETA_CORE_JSONSCHEMA_EXPORT Frame {
113113
/// have a static and a dynamic reference to the same location
114114
/// on the same schema object.
115115
using References =
116-
std::map<std::pair<ReferenceType, Pointer>, ReferencesEntry>;
116+
std::map<std::pair<SchemaReferenceType, Pointer>, ReferencesEntry>;
117117

118118
#if defined(__GNUC__)
119119
#pragma GCC diagnostic push
@@ -150,7 +150,7 @@ class SOURCEMETA_CORE_JSONSCHEMA_EXPORT Frame {
150150
/// JSON Pointers within the schema, and subschemas dialects. We call it
151151
/// reference frame as this mapping is essential for resolving references.
152152
using Locations =
153-
std::map<std::pair<ReferenceType, std::string>, LocationsEntry>;
153+
std::map<std::pair<SchemaReferenceType, std::string>, LocationsEntry>;
154154

155155
/// Analyse a given schema
156156
auto analyse(const JSON &schema, const SchemaWalker &walker,
@@ -188,7 +188,7 @@ class SOURCEMETA_CORE_JSONSCHEMA_EXPORT Frame {
188188
auto
189189
dereference(const LocationsEntry &location,
190190
const Pointer &relative_schema_location = empty_pointer) const
191-
-> std::pair<ReferenceType,
191+
-> std::pair<SchemaReferenceType,
192192
std::optional<std::reference_wrapper<const LocationsEntry>>>;
193193

194194
private:

src/core/jsonschema/include/sourcemeta/core/jsonschema_keywords.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace sourcemeta::core {
1414
#endif
1515
/// @ingroup jsonschema
1616
/// Determines the type of a JSON Schema keyword
17-
enum class KeywordType : std::uint8_t {
17+
enum class SchemaKeywordType : std::uint8_t {
1818
/// The JSON Schema keyword is unknown
1919
Unknown,
2020
/// The JSON Schema keyword is a non-applicator assertion

src/core/jsonschema/include/sourcemeta/core/jsonschema_reference.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace sourcemeta::core {
77

88
/// @ingroup jsonschema
99
/// The reference type
10-
enum class ReferenceType : std::uint8_t { Static, Dynamic };
10+
enum class SchemaReferenceType : std::uint8_t { Static, Dynamic };
1111

1212
} // namespace sourcemeta::core
1313

src/core/jsonschema/include/sourcemeta/core/jsonschema_resolver.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ auto official_resolver(std::string_view identifier)
4747
/// #include <cassert>
4848
///
4949
/// // (1) Create a map resolver that falls back to the official resolver
50-
/// sourcemeta::core::MapSchemaResolver
50+
/// sourcemeta::core::SchemaMapResolver
5151
/// resolver{sourcemeta::core::official_resolver};
5252
///
5353
/// const sourcemeta::core::JSON schema =
@@ -62,14 +62,14 @@ auto official_resolver(std::string_view identifier)
6262
///
6363
/// assert(resolver("https://www.example.com").has_value());
6464
/// ```
65-
class SOURCEMETA_CORE_JSONSCHEMA_EXPORT MapSchemaResolver {
65+
class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaMapResolver {
6666
public:
6767
/// Construct an empty resolver. If you don't add schemas to it, it will
6868
/// always resolve to nothing
69-
MapSchemaResolver();
69+
SchemaMapResolver();
7070

7171
/// Construct an empty resolver that has another schema resolver as a fallback
72-
MapSchemaResolver(const SchemaResolver &resolver);
72+
SchemaMapResolver(const SchemaResolver &resolver);
7373

7474
/// Register a schema to the map resolver
7575
auto add(const JSON &schema,
@@ -104,22 +104,22 @@ class SOURCEMETA_CORE_JSONSCHEMA_EXPORT MapSchemaResolver {
104104
/// #include <cassert>
105105
///
106106
/// // (1) Create a flat file resolver that falls back to the official resolver
107-
/// sourcemeta::core::FlatFileSchemaResolver
107+
/// sourcemeta::core::SchemaFlatFileResolver
108108
/// resolver{sourcemeta::core::official_resolver};
109109
///
110110
/// // (2) Register a schema by path
111111
/// resolver.add("path/to/example.schema.json");
112112
///
113113
/// assert(resolver("https://www.example.com").has_value());
114114
/// ```
115-
class SOURCEMETA_CORE_JSONSCHEMA_EXPORT FlatFileSchemaResolver {
115+
class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaFlatFileResolver {
116116
public:
117117
/// Construct an empty resolver. If you don't add schemas to it, it will
118118
/// always resolve to nothing
119-
FlatFileSchemaResolver();
119+
SchemaFlatFileResolver();
120120

121121
/// Construct an empty resolver that has another schema resolver as a fallback
122-
FlatFileSchemaResolver(const SchemaResolver &resolver);
122+
SchemaFlatFileResolver(const SchemaResolver &resolver);
123123

124124
/// Determines how to access the registered file entry, letting you hook
125125
/// into how schemas are read to support other file formats, like YAML

src/core/jsonschema/include/sourcemeta/core/jsonschema_unevaluated.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
namespace sourcemeta::core {
2020

2121
/// @ingroup jsonschema
22-
struct UnevaluatedEntry {
22+
struct SchemaUnevaluatedEntry {
2323
/// The absolute pointers of the static keyword dependencies
2424
std::set<Pointer> static_dependencies;
2525
/// The absolute pointers of the static keyword dependencies
@@ -31,7 +31,7 @@ struct UnevaluatedEntry {
3131

3232
/// @ingroup jsonschema
3333
/// The flattened set of unevaluated cases in the schema by absolute URI
34-
using UnevaluatedEntries = std::map<std::string, UnevaluatedEntry>;
34+
using SchemaUnevaluatedEntries = std::map<std::string, SchemaUnevaluatedEntry>;
3535

3636
// TODO: Eventually generalize this to list every cross-dependency between
3737
// keywords, supporting extensibility of custom vocabularies too
@@ -54,7 +54,7 @@ using UnevaluatedEntries = std::map<std::string, UnevaluatedEntry>;
5454
/// "unevaluatedProperties": false
5555
/// })JSON");
5656
///
57-
/// sourcemeta::core::Frame frame;
57+
/// sourcemeta::core::SchemaSchemaFrame frame;
5858
/// frame.analyse(document,
5959
/// sourcemeta::core::default_schema_walker,
6060
/// sourcemeta::core::official_resolver);
@@ -67,9 +67,9 @@ using UnevaluatedEntries = std::map<std::string, UnevaluatedEntry>;
6767
/// assert(!result.at("#/unevaluatedProperties").dynamic);
6868
/// assert(result.at("#/unevaluatedProperties").dependencies.empty());
6969
/// ```
70-
auto SOURCEMETA_CORE_JSONSCHEMA_EXPORT
71-
unevaluated(const JSON &schema, const Frame &frame, const SchemaWalker &walker,
72-
const SchemaResolver &resolver) -> UnevaluatedEntries;
70+
auto SOURCEMETA_CORE_JSONSCHEMA_EXPORT unevaluated(
71+
const JSON &schema, const SchemaFrame &frame, const SchemaWalker &walker,
72+
const SchemaResolver &resolver) -> SchemaUnevaluatedEntries;
7373

7474
} // namespace sourcemeta::core
7575

src/core/jsonschema/include/sourcemeta/core/jsonschema_walker.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace sourcemeta::core {
2525
/// A structure that encapsulates the result of walker over a specific keyword
2626
struct SchemaWalkerResult {
2727
/// The walker strategy to continue traversing across the schema
28-
const KeywordType type;
28+
const SchemaKeywordType type;
2929
/// The vocabulary associated with the keyword, if any
3030
const std::optional<std::string> vocabulary;
3131
/// The keywords a given keyword depends on (if any) during the evaluation
@@ -54,7 +54,7 @@ SOURCEMETA_CORE_JSONSCHEMA_EXPORT
5454
inline auto schema_walker_none(std::string_view,
5555
const std::map<std::string, bool> &)
5656
-> sourcemeta::core::SchemaWalkerResult {
57-
return {KeywordType::Unknown, std::nullopt, {}};
57+
return {SchemaKeywordType::Unknown, std::nullopt, {}};
5858
}
5959

6060
/// @ingroup jsonschema
@@ -233,16 +233,16 @@ class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaIteratorFlat {
233233
/// sourcemeta::core::vocabularies(
234234
/// document, sourcemeta::core::official_resolver)};
235235
///
236-
/// assert(sourcemeta::core::keyword_priority(
236+
/// assert(sourcemeta::core::schema_keyword_priority(
237237
/// "prefixItems", vocabularies,
238238
/// sourcemeta::core::default_schema_walker) == 0);
239239
///
240240
/// // The "items" keyword must be evaluated after the "prefixItems" keyword
241-
/// assert(sourcemeta::core::keyword_priority(
241+
/// assert(sourcemeta::core::schema_keyword_priority(
242242
/// "items", vocabularies,
243243
/// sourcemeta::core::default_schema_walker) == 1);
244244
/// ```
245-
auto SOURCEMETA_CORE_JSONSCHEMA_EXPORT keyword_priority(
245+
auto SOURCEMETA_CORE_JSONSCHEMA_EXPORT schema_keyword_priority(
246246
std::string_view keyword, const std::map<std::string, bool> &vocabularies,
247247
const SchemaWalker &walker) -> std::uint64_t;
248248

src/core/jsonschema/jsonschema.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static auto id_keyword(const std::string &base_dialect) -> std::string {
5757

5858
auto sourcemeta::core::identify(
5959
const sourcemeta::core::JSON &schema, const SchemaResolver &resolver,
60-
const IdentificationStrategy strategy,
60+
const SchemaIdentificationStrategy strategy,
6161
const std::optional<std::string> &default_dialect,
6262
const std::optional<std::string> &default_id)
6363
-> std::optional<std::string> {
@@ -70,7 +70,7 @@ auto sourcemeta::core::identify(
7070
sourcemeta::core::base_dialect(schema, resolver, default_dialect);
7171
} catch (const SchemaResolutionError &) {
7272
// Attempt to play a heuristic guessing game before giving up
73-
if (strategy == IdentificationStrategy::Loose && schema.is_object()) {
73+
if (strategy == SchemaIdentificationStrategy::Loose && schema.is_object()) {
7474
const auto keyword{id_keyword_guess(schema)};
7575
if (keyword.has_value()) {
7676
return schema.at(keyword.value()).to_string();
@@ -84,7 +84,7 @@ auto sourcemeta::core::identify(
8484

8585
if (!maybe_base_dialect.has_value()) {
8686
// Attempt to play a heuristic guessing game before giving up
87-
if (strategy == IdentificationStrategy::Loose && schema.is_object()) {
87+
if (strategy == SchemaIdentificationStrategy::Loose && schema.is_object()) {
8888
const auto keyword{id_keyword_guess(schema)};
8989
if (keyword.has_value()) {
9090
return schema.at(keyword.value()).to_string();

0 commit comments

Comments
 (0)