From 67263029946e4e5cc0f94eb33e7f2262c213a932 Mon Sep 17 00:00:00 2001 From: Martin Morgan Date: Tue, 2 Apr 2024 20:53:57 -0400 Subject: [PATCH 1/2] make schema error quotation and punctuation more consistent --- .../jsonschema/common/format_validator.hpp | 16 ++++++++-------- .../jsonschema/common/keyword_validators.hpp | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/jsoncons_ext/jsonschema/common/format_validator.hpp b/include/jsoncons_ext/jsonschema/common/format_validator.hpp index 4d32f54e3..980385205 100644 --- a/include/jsoncons_ext/jsonschema/common/format_validator.hpp +++ b/include/jsoncons_ext/jsonschema/common/format_validator.hpp @@ -902,7 +902,7 @@ namespace jsonschema { eval_path, schema_location, instance_location, - "\"" + value + "\" is not a RFC 3339 date string")); + "'" + value + "' is not a RFC 3339 date string.")); } } @@ -918,7 +918,7 @@ namespace jsonschema { eval_path, schema_location, instance_location, - "\"" + value + "\" is not a RFC 3339 time string")); + "'" + value + "' is not a RFC 3339 time string.")); } } @@ -934,7 +934,7 @@ namespace jsonschema { eval_path, schema_location, instance_location, - "\"" + value + "\" is not a RFC 3339 date-time string")); + "'" + value + "' is not a RFC 3339 date-time string.")); } } @@ -950,7 +950,7 @@ namespace jsonschema { eval_path, schema_location, instance_location, - "\"" + value + "\" is not a valid email address as defined by RFC 5322")); + "'" + value + "' is not a valid email address as defined by RFC 5322.")); } } @@ -966,7 +966,7 @@ namespace jsonschema { eval_path, schema_location, instance_location, - "\"" + value + "\" is not a valid hostname as defined by RFC 3986 Appendix A")); + "'" + value + "' is not a valid hostname as defined by RFC 3986 Appendix A.")); } } @@ -982,7 +982,7 @@ namespace jsonschema { eval_path, schema_location, instance_location, - "\"" + value + "\" is not a valid IPv4 address as defined by RFC 2673")); + "'" + value + "' is not a valid IPv4 address as defined by RFC 2673.")); } } @@ -998,7 +998,7 @@ namespace jsonschema { eval_path, schema_location, instance_location, - "\"" + value + "\" is not a valid IPv6 address as defined by RFC 2373")); + "'" + value + "' is not a valid IPv6 address as defined by RFC 2373.")); } } @@ -1019,7 +1019,7 @@ namespace jsonschema { eval_path, schema_location, instance_location, - "\"" + value + "\" is not a valid ECMAScript regular expression. " + e.what())); + "'" + value + "' is not a valid ECMAScript regular expression. " + e.what())); } #endif } diff --git a/include/jsoncons_ext/jsonschema/common/keyword_validators.hpp b/include/jsoncons_ext/jsonschema/common/keyword_validators.hpp index 783882539..db0e63b01 100644 --- a/include/jsoncons_ext/jsonschema/common/keyword_validators.hpp +++ b/include/jsoncons_ext/jsonschema/common/keyword_validators.hpp @@ -363,11 +363,11 @@ namespace jsonschema { auto s = instance.template as(); if (!std::regex_search(s, regex_)) { - std::string message("String \""); + std::string message("String '"); message.append(s); - message.append("\" does not match pattern \""); + message.append("' does not match pattern '"); message.append(pattern_string_); - message.append("\""); + message.append("'."); reporter.error(validation_message(this->keyword_name(), this_context.eval_path(), this->schema_location(), @@ -1303,7 +1303,7 @@ namespace jsonschema { this_context.eval_path(), this->schema_location(), instance_location, - "Required property \"" + key + "\" not found")); + "Required property '" + key + "' not found.")); if(reporter.fail_early()) { return; @@ -1510,7 +1510,7 @@ namespace jsonschema { this_context.eval_path(), this->schema_location(), instance_location, - instance.template as() + " is not a valid enum value")); + "'" + instance.template as() + "' is not a valid enum value.")); if (reporter.fail_early()) { return; @@ -1994,7 +1994,7 @@ namespace jsonschema { prop_context.eval_path(), this->schema_location(), prop_location, - "Additional property '" + prop.key() + "' but the schema does not allow additional properties.")); + "Additional property '" + prop.key() + "' not allowed by schema.")); break; } } @@ -2033,7 +2033,7 @@ namespace jsonschema { this_context.eval_path(), additional_properties_->schema_location().string(), instance_location, - "Additional property \"" + prop.key() + "\" found but was invalid.")); + "Additional property '" + prop.key() + "' found but was invalid.")); if (reporter.fail_early()) { return; @@ -2396,7 +2396,7 @@ namespace jsonschema { this_context.eval_path(), this->schema_location(), instance_location, - "Expected at least one array item to match \"contains\" schema", + "Expected at least one array item to match 'contains' schema.", local_reporter.errors)); if (reporter.fail_early()) { From fdd6e66a250f1112eaf27fa6e342effc2ed50746 Mon Sep 17 00:00:00 2001 From: Martin Morgan Date: Tue, 2 Apr 2024 22:17:01 -0400 Subject: [PATCH 2/2] update unit test --- test/jsonschema/src/validation_report_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jsonschema/src/validation_report_tests.cpp b/test/jsonschema/src/validation_report_tests.cpp index d070f9528..22ab769c9 100644 --- a/test/jsonschema/src/validation_report_tests.cpp +++ b/test/jsonschema/src/validation_report_tests.cpp @@ -177,7 +177,7 @@ TEST_CASE("jsonschema additionalProperties output tests") "evaluationPath": "/additionalProperties/direction", "schemaLocation": "#", "instanceLocation": "/direction", - "error": "Additional property 'direction' but the schema does not allow additional properties." + "error": "Additional property 'direction' not allowed by schema." } ] )");