Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/core/jsonschema/known_walker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,10 @@ auto handle_requires(const Vocabularies &vocabularies)

auto handle_optional(const Vocabularies &vocabularies)
-> const SchemaWalkerResult & {
CHECK_VOCABULARY(Known::JSON_Schema_Draft_2, make_set({JSON::Type::Object}),
Assertion)
CHECK_VOCABULARY(Known::JSON_Schema_Draft_2_Hyper,
make_set({JSON::Type::Object}), Assertion)
CHECK_VOCABULARY(Known::JSON_Schema_Draft_1, make_set({JSON::Type::Object}),
Assertion)
CHECK_VOCABULARY(Known::JSON_Schema_Draft_1_Hyper,
Expand Down
25 changes: 25 additions & 0 deletions test/jsonschema/jsonschema_walker_draft2_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,18 @@ TEST(JSONSchema_walker_draft2, requires) {
sourcemeta::core::make_set({sourcemeta::core::JSON::Type::Object}));
}

TEST(JSONSchema_walker_draft2, optional) {
using namespace sourcemeta::core;
const auto &result{schema_walker("optional", VOCABULARIES_DRAFT2)};
EXPECT_EQ(result.type, SchemaKeywordType::Assertion);
EXPECT_TRUE(result.vocabulary.has_value());
EXPECT_VOCABULARY_KNOWN(result.vocabulary.value(), JSON_Schema_Draft_2);
EXPECT_TRUE(result.dependencies.empty());
EXPECT_TRUE(result.order_dependencies.empty());
EXPECT_EQ(result.instances,
sourcemeta::core::make_set({sourcemeta::core::JSON::Type::Object}));
}

TEST(JSONSchema_walker_draft2, format) {
using namespace sourcemeta::core;
const auto &result{schema_walker("format", VOCABULARIES_DRAFT2)};
Expand Down Expand Up @@ -713,6 +725,19 @@ TEST(JSONSchema_walker_draft2, hyperschema_requires) {
sourcemeta::core::make_set({sourcemeta::core::JSON::Type::Object}));
}

TEST(JSONSchema_walker_draft2, hyperschema_optional) {
using namespace sourcemeta::core;
const auto &result{
schema_walker("optional", VOCABULARIES_DRAFT2_HYPERSCHEMA)};
EXPECT_EQ(result.type, SchemaKeywordType::Assertion);
EXPECT_TRUE(result.vocabulary.has_value());
EXPECT_VOCABULARY_KNOWN(result.vocabulary.value(), JSON_Schema_Draft_2_Hyper);
EXPECT_TRUE(result.dependencies.empty());
EXPECT_TRUE(result.order_dependencies.empty());
EXPECT_EQ(result.instances,
sourcemeta::core::make_set({sourcemeta::core::JSON::Type::Object}));
}

TEST(JSONSchema_walker_draft2, hyperschema_format) {
using namespace sourcemeta::core;
const auto &result{schema_walker("format", VOCABULARIES_DRAFT2_HYPERSCHEMA)};
Expand Down
Loading