json: default additionalProperty to true
This commit is contained in:
parent
e95beeb1fc
commit
12a061c8eb
4 changed files with 28 additions and 5 deletions
|
@ -625,7 +625,7 @@ public:
|
|||
return _add_rule(rule_name,
|
||||
_build_object_rule(
|
||||
properties, required, name,
|
||||
schema.contains("additionalProperties") ? schema["additionalProperties"] : json()));
|
||||
schema.contains("additionalProperties") ? schema["additionalProperties"] : json::object()));
|
||||
} else if ((schema_type.is_null() || schema_type == "object") && schema.contains("allOf")) {
|
||||
std::unordered_set<std::string> required;
|
||||
std::vector<std::pair<std::string, json>> properties;
|
||||
|
|
|
@ -372,7 +372,10 @@ class SchemaConverter:
|
|||
('additionalProperties' in schema and schema['additionalProperties'] is not True)):
|
||||
required = set(schema.get('required', []))
|
||||
properties = list(schema.get('properties', {}).items())
|
||||
return self._add_rule(rule_name, self._build_object_rule(properties, required, name, schema.get('additionalProperties')))
|
||||
additional_properties = schema.get('additionalProperties', True)
|
||||
if additional_properties is None:
|
||||
additional_properties = True
|
||||
return self._add_rule(rule_name, self._build_object_rule(properties, required, name, additional_properties))
|
||||
|
||||
elif schema_type in (None, 'object') and 'allOf' in schema:
|
||||
required = set()
|
||||
|
|
|
@ -374,7 +374,11 @@ export class SchemaConverter {
|
|||
('additionalProperties' in schema && schema.additionalProperties !== true))) {
|
||||
const required = new Set(schema.required || []);
|
||||
const properties = Object.entries(schema.properties ?? {});
|
||||
return this._addRule(ruleName, this._buildObjectRule(properties, required, name, schema.additionalProperties));
|
||||
let additionalProperties = schema.additionalProperties;
|
||||
if (additionalProperties === undefined) {
|
||||
additionalProperties = true;
|
||||
}
|
||||
return this._addRule(ruleName, this._buildObjectRule(properties, required, name, additionalProperties));
|
||||
} else if ((schemaType === undefined || schemaType === 'object') && 'allOf' in schema) {
|
||||
const required = new Set();
|
||||
const properties = [];
|
||||
|
|
|
@ -751,15 +751,31 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
|
|||
R"""(
|
||||
alternative-0 ::= foo
|
||||
alternative-1 ::= bar
|
||||
bar ::= "{" space (bar-b-kv )? "}" space
|
||||
array ::= "[" space ( value ("," space value)* )? "]" space
|
||||
bar ::= "{" space (bar-b-kv bar-b-rest | bar-additional-kvs )? "}" space
|
||||
bar-additional-kv ::= string ":" space bar-additional-value
|
||||
bar-additional-kvs ::= bar-additional-kv ( "," space bar-additional-kv )*
|
||||
bar-additional-value ::= object
|
||||
bar-b-kv ::= "\"b\"" space ":" space number
|
||||
bar-b-rest ::= bar-additional-kvs
|
||||
boolean ::= ("true" | "false") space
|
||||
char ::= [^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F]{4})
|
||||
decimal-part ::= [0-9]{1,16}
|
||||
foo ::= "{" space (foo-a-kv )? "}" space
|
||||
foo ::= "{" space (foo-a-kv foo-a-rest | foo-additional-kvs )? "}" space
|
||||
foo-a-kv ::= "\"a\"" space ":" space number
|
||||
foo-a-rest ::= foo-additional-kvs
|
||||
foo-additional-kv ::= string ":" space foo-additional-value
|
||||
foo-additional-kvs ::= foo-additional-kv ( "," space foo-additional-kv )*
|
||||
foo-additional-value ::= object
|
||||
integral-part ::= [0] | [1-9] [0-9]{0,15}
|
||||
null ::= "null" space
|
||||
number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
|
||||
object ::= "{" space ( string ":" space value ("," space string ":" space value)* )? "}" space
|
||||
root ::= alternative-0 | alternative-1
|
||||
space ::= " "?
|
||||
string ::= "\"" char* "\"" space
|
||||
value ::= object | array | string | number | boolean | null
|
||||
|
||||
)"""
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue