Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
227 changes: 114 additions & 113 deletions src/alterschema/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,125 +1,126 @@
sourcemeta_library(NAMESPACE sourcemeta PROJECT blaze NAME alterschema
FOLDER "Blaze/AlterSchema"
PRIVATE_HEADERS error.h
SOURCES alterschema.cc schema_rule.cc
# Canonicalizer
canonicalizer/const_as_enum.h
canonicalizer/exclusive_maximum_integer_to_maximum.h
canonicalizer/exclusive_minimum_integer_to_minimum.h
canonicalizer/items_implicit.h
canonicalizer/max_contains_covered_by_max_items.h
canonicalizer/min_items_given_min_contains.h
canonicalizer/min_items_implicit.h
canonicalizer/min_length_implicit.h
canonicalizer/min_properties_covered_by_required.h
canonicalizer/min_properties_implicit.h
canonicalizer/multiple_of_implicit.h
canonicalizer/properties_implicit.h
canonicalizer/type_array_to_any_of.h
canonicalizer/type_boolean_as_enum.h
canonicalizer/type_null_as_enum.h
canonicalizer/type_union_implicit.h
FOLDER "Blaze/AlterSchema"
PRIVATE_HEADERS error.h
SOURCES alterschema.cc schema_rule.cc
# Canonicalizer
canonicalizer/const_as_enum.h
canonicalizer/exclusive_maximum_integer_to_maximum.h
canonicalizer/exclusive_minimum_integer_to_minimum.h
canonicalizer/items_implicit.h
canonicalizer/max_contains_covered_by_max_items.h
canonicalizer/min_items_given_min_contains.h
canonicalizer/min_items_implicit.h
canonicalizer/min_length_implicit.h
canonicalizer/min_properties_covered_by_required.h
canonicalizer/min_properties_implicit.h
canonicalizer/multiple_of_implicit.h
canonicalizer/properties_implicit.h
canonicalizer/type_array_to_any_of.h
canonicalizer/type_boolean_as_enum.h
canonicalizer/type_null_as_enum.h
canonicalizer/type_union_implicit.h

# Common
common/allof_false_simplify.h
common/anyof_false_simplify.h
common/anyof_remove_false_schemas.h
common/anyof_true_simplify.h
common/const_in_enum.h
common/const_with_type.h
common/orphan_definitions.h
common/content_media_type_without_encoding.h
common/content_schema_without_media_type.h
common/dependencies_property_tautology.h
common/dependent_required_tautology.h
common/draft_official_dialect_with_https.h
common/draft_official_dialect_without_empty_fragment.h
common/draft_ref_siblings.h
common/drop_allof_empty_schemas.h
common/duplicate_allof_branches.h
common/duplicate_anyof_branches.h
common/duplicate_enum_values.h
common/duplicate_required_values.h
common/empty_object_as_true.h
common/else_empty.h
common/else_without_if.h
common/enum_with_type.h
common/equal_numeric_bounds_to_enum.h
common/exclusive_maximum_number_and_maximum.h
common/exclusive_minimum_number_and_minimum.h
common/if_without_then_else.h
common/ignored_metaschema.h
common/max_contains_without_contains.h
common/maximum_real_for_integer.h
common/min_contains_without_contains.h
common/minimum_real_for_integer.h
common/modern_official_dialect_with_empty_fragment.h
common/modern_official_dialect_with_http.h
common/non_applicable_additional_items.h
common/non_applicable_enum_validation_keywords.h
common/non_applicable_type_specific_keywords.h
common/not_false.h
common/oneof_false_simplify.h
common/oneof_to_anyof_disjoint_types.h
common/required_properties_in_properties.h
common/single_type_array.h
common/then_empty.h
common/then_without_if.h
common/unknown_keywords_prefix.h
common/unknown_local_ref.h
common/unsatisfiable_drop_validation.h
common/unnecessary_allof_ref_wrapper_draft.h
common/unnecessary_allof_ref_wrapper_modern.h
common/unnecessary_allof_wrapper.h
common/unsatisfiable_in_place_applicator_type.h
# Common
common/allof_false_simplify.h
common/anyof_false_simplify.h
common/anyof_remove_false_schemas.h
common/anyof_true_simplify.h
common/const_in_enum.h
common/const_with_type.h
common/orphan_definitions.h
common/content_media_type_without_encoding.h
common/content_schema_without_media_type.h
common/dependencies_property_tautology.h
common/dependent_required_tautology.h
common/draft_official_dialect_with_https.h
common/draft_official_dialect_without_empty_fragment.h
common/draft_ref_siblings.h
common/drop_allof_empty_schemas.h
common/duplicate_allof_branches.h
common/duplicate_anyof_branches.h
common/duplicate_enum_values.h
common/duplicate_required_values.h
common/empty_object_as_true.h
common/else_empty.h
common/else_without_if.h
common/enum_with_type.h
common/equal_numeric_bounds_to_enum.h
common/exclusive_maximum_number_and_maximum.h
common/exclusive_minimum_number_and_minimum.h
common/if_without_then_else.h
common/ignored_metaschema.h
common/max_contains_without_contains.h
common/maximum_real_for_integer.h
common/min_contains_without_contains.h
common/minimum_real_for_integer.h
common/modern_official_dialect_with_empty_fragment.h
common/modern_official_dialect_with_http.h
common/non_applicable_additional_items.h
common/non_applicable_enum_validation_keywords.h
common/non_applicable_type_specific_keywords.h
common/not_false.h
common/oneof_false_simplify.h
common/oneof_to_anyof_disjoint_types.h
common/required_properties_in_properties.h
common/single_type_array.h
common/then_empty.h
common/then_without_if.h
common/unknown_keywords_prefix.h
common/unknown_local_ref.h
common/unsatisfiable_drop_validation.h
common/unnecessary_allof_ref_wrapper_draft.h
common/unnecessary_allof_ref_wrapper_modern.h
common/unnecessary_allof_wrapper.h
common/unsatisfiable_in_place_applicator_type.h

# Linter
linter/comment_trim.h
linter/const_not_in_enum.h
linter/content_schema_default.h
linter/definitions_to_defs.h
linter/dependencies_default.h
linter/dependent_required_default.h
linter/description_trailing_period.h
linter/description_trim.h
linter/duplicate_examples.h
linter/enum_to_const.h
linter/equal_numeric_bounds_to_const.h
linter/forbid_empty_enum.h
linter/incoherent_min_max_contains.h
linter/invalid_external_ref.h
linter/items_array_default.h
linter/items_schema_default.h
linter/multiple_of_default.h
linter/pattern_properties_default.h
linter/properties_default.h
linter/property_names_default.h
linter/property_names_type_default.h
linter/simple_properties_identifiers.h
linter/title_description_equal.h
linter/title_trailing_period.h
linter/title_trim.h
linter/top_level_description.h
linter/top_level_examples.h
linter/top_level_title.h
linter/unevaluated_items_default.h
linter/unevaluated_properties_default.h
linter/unsatisfiable_max_contains.h
linter/unsatisfiable_min_properties.h
linter/valid_default.h
linter/valid_examples.h)
# Linter
linter/comment_trim.h
linter/const_not_in_enum.h
linter/content_schema_default.h
linter/definitions_to_defs.h
linter/dependencies_default.h
linter/dependent_required_default.h
linter/description_trailing_period.h
linter/description_trim.h
linter/duplicate_examples.h
linter/enum_to_const.h
linter/equal_numeric_bounds_to_const.h
linter/forbid_empty_enum.h
linter/format_type_mismatch.h
linter/incoherent_min_max_contains.h
linter/invalid_external_ref.h
linter/items_array_default.h
linter/items_schema_default.h
linter/multiple_of_default.h
linter/pattern_properties_default.h
linter/properties_default.h
linter/property_names_default.h
linter/property_names_type_default.h
linter/simple_properties_identifiers.h
linter/title_description_equal.h
linter/title_trailing_period.h
linter/title_trim.h
linter/top_level_description.h
linter/top_level_examples.h
linter/top_level_title.h
linter/unevaluated_items_default.h
linter/unevaluated_properties_default.h
linter/unsatisfiable_max_contains.h
linter/unsatisfiable_min_properties.h
linter/valid_default.h
linter/valid_examples.h)

if(BLAZE_INSTALL)
sourcemeta_library_install(NAMESPACE sourcemeta PROJECT blaze NAME alterschema)
sourcemeta_library_install(NAMESPACE sourcemeta PROJECT blaze NAME alterschema)
endif()

target_link_libraries(sourcemeta_blaze_alterschema PUBLIC
sourcemeta::core::jsonschema)
sourcemeta::core::jsonschema)
target_link_libraries(sourcemeta_blaze_alterschema PUBLIC
sourcemeta::blaze::compiler)
sourcemeta::blaze::compiler)
target_link_libraries(sourcemeta_blaze_alterschema PRIVATE
sourcemeta::blaze::evaluator)
sourcemeta::blaze::evaluator)
target_link_libraries(sourcemeta_blaze_alterschema PRIVATE
sourcemeta::blaze::output)
sourcemeta::blaze::output)
target_link_libraries(sourcemeta_blaze_alterschema PRIVATE
sourcemeta::core::regex)
sourcemeta::core::regex)
2 changes: 2 additions & 0 deletions src/alterschema/alterschema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ inline auto APPLIES_TO_POINTERS(std::vector<Pointer> &&keywords)
#include "linter/enum_to_const.h"
#include "linter/equal_numeric_bounds_to_const.h"
#include "linter/forbid_empty_enum.h"
#include "linter/format_type_mismatch.h"
#include "linter/incoherent_min_max_contains.h"
#include "linter/invalid_external_ref.h"
#include "linter/items_array_default.h"
Expand Down Expand Up @@ -248,6 +249,7 @@ auto add(sourcemeta::core::SchemaTransformer &bundle,
bundle.add<UnsatisfiableMinProperties>();
bundle.add<EnumToConst>();
bundle.add<ForbidEmptyEnum>();
bundle.add<FormatTypeMismatch>();
bundle.add<TopLevelTitle>();
bundle.add<TopLevelDescription>();
bundle.add<TopLevelExamples>();
Expand Down
33 changes: 33 additions & 0 deletions src/alterschema/linter/format_type_mismatch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class FormatTypeMismatch final : public SchemaTransformRule {
public:
using mutates = std::false_type;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this should have a transform: delete the format

using reframe_after_transform = std::false_type;
FormatTypeMismatch()
: SchemaTransformRule{
"format_type_mismatch",
"The `format` keyword validates string instances but `type` "
"is not `string`"} {};

[[nodiscard]] auto
condition(const sourcemeta::core::JSON &schema,
const sourcemeta::core::JSON &,
const sourcemeta::core::Vocabularies &vocabularies,
const sourcemeta::core::SchemaFrame &,
const sourcemeta::core::SchemaFrame::Location &,
const sourcemeta::core::SchemaWalker &,
const sourcemeta::core::SchemaResolver &) const
-> sourcemeta::core::SchemaTransformRule::Result override {
using Known = Vocabularies::Known;
ONLY_CONTINUE_IF(
vocabularies.contains_any(
{Known::JSON_Schema_2020_12_Validation,
Known::JSON_Schema_2019_09_Validation, Known::JSON_Schema_Draft_7,
Known::JSON_Schema_Draft_6, Known::JSON_Schema_Draft_4,
Known::JSON_Schema_Draft_3}) &&
schema.is_object() && schema.defines("type") &&
schema.at("type").is_string() &&
schema.at("type").to_string() != "string" && schema.defines("format") &&
schema.at("format").is_string());
return APPLIES_TO_KEYWORDS("format", "type");
}
};
Loading
Loading