jsonschema: Add additionalProperties option#117
Conversation
Use `additionalProperties` instead of `unevaluatedProperties` (and flatten property list, as `additionalProperties` needs it) Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||
|
Size comparison for the generated JSON Schema, using SPDX models as example:
@goneall you may use the generated schema (additionalProperties version) to test your SPDX document if it improves the performance of case in networknt/json-schema-validator#1216. |
|
Generated JSON Schema snippets for comparison (from SPDX 3.0 model): Default (without "software_File": {
"if": {
"type": "object",
"properties": {
"type": {
"const": "software_File"
}
},
"required": ["type"]
},
"then": {
"allOf": [
{
"type": "object",
"properties": {
"spdxId": { "$ref": "#/$defs/IRI" },
"type": { "type": "string" }
},
"required": ["spdxId"]
},
{ "$ref": "#/$defs/software_File_props" }
]
},
"else": {
"const": "Not a software_File"
}
},
"software_File_props": {
"allOf": [
{ "$ref": "#/$defs/software_SoftwareArtifact_props" },
{
"type": "object",
"properties": {
"contentType": {
"$ref": "#/$defs/prop_software_File_contentType"
},
"software_fileKind": {
"$ref": "#/$defs/prop_software_File_software_fileKind"
}
}
}
]
},With "software_File": {
"if": {
"type": "object",
"properties": {
"type": {
"const": "software_File"
}
},
"required": ["type"]
},
"then": {
"type": "object",
"properties": {
"spdxId": { "$ref": "#/$defs/IRI" },
"type": { "type": "string" },
"@context": {},
"comment": {
"$ref": "#/$defs/prop_Element_comment"
},
"creationInfo": {
"$ref": "#/$defs/prop_Element_creationInfo"
},
"description": {
"$ref": "#/$defs/prop_Element_description"
},
"extension": {
"anyOf": [
{
"type": "array",
"items": {
"$ref": "#/$defs/prop_Element_extension"
}
}
]
},
"externalIdentifier": {
"anyOf": [
{
"type": "array",
"items": {
"$ref": "#/$defs/prop_Element_externalIdentifier"
}
}
]
},
"externalRef": {
"anyOf": [
{
"type": "array",
"items": {
"$ref": "#/$defs/prop_Element_externalRef"
}
}
]
},
"name": {
"$ref": "#/$defs/prop_Element_name"
},
"summary": {
"$ref": "#/$defs/prop_Element_summary"
},
"verifiedUsing": {
"anyOf": [
{
"type": "array",
"items": {
"$ref": "#/$defs/prop_Element_verifiedUsing"
}
}
]
},
"builtTime": {
"$ref": "#/$defs/prop_Artifact_builtTime"
},
"originatedBy": {
"anyOf": [
{
"type": "array",
"items": {
"$ref": "#/$defs/prop_Artifact_originatedBy"
}
}
]
},
"releaseTime": {
"$ref": "#/$defs/prop_Artifact_releaseTime"
},
"standardName": {
"anyOf": [
{
"type": "array",
"items": {
"$ref": "#/$defs/prop_Artifact_standardName"
}
}
]
},
"suppliedBy": {
"$ref": "#/$defs/prop_Artifact_suppliedBy"
},
"supportLevel": {
"anyOf": [
{
"type": "array",
"items": {
"$ref": "#/$defs/prop_Artifact_supportLevel"
}
}
]
},
"validUntilTime": {
"$ref": "#/$defs/prop_Artifact_validUntilTime"
},
"software_additionalPurpose": {
"anyOf": [
{
"type": "array",
"items": {
"$ref": "#/$defs/prop_software_SoftwareArtifact_software_additionalPurpose"
}
}
]
},
"software_attributionText": {
"anyOf": [
{
"type": "array",
"items": {
"$ref": "#/$defs/prop_software_SoftwareArtifact_software_attributionText"
}
}
]
},
"software_contentIdentifier": {
"anyOf": [
{
"type": "array",
"items": {
"$ref": "#/$defs/prop_software_SoftwareArtifact_software_contentIdentifier"
}
}
]
},
"software_copyrightText": {
"$ref": "#/$defs/prop_software_SoftwareArtifact_software_copyrightText"
},
"software_primaryPurpose": {
"$ref": "#/$defs/prop_software_SoftwareArtifact_software_primaryPurpose"
},
"contentType": {
"$ref": "#/$defs/prop_software_File_contentType"
},
"software_fileKind": {
"$ref": "#/$defs/prop_software_File_software_fileKind"
}
},
"required": [
"spdxId",
"creationInfo"
],
"additionalProperties": false
},
"else": {
"const": "Not a software_File"
}
}, |
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
|
After the merge of test_ajv_compile, the test is broken. |
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
|
FYI, I did see this, but I want to have a good think about it. It's a lot of extra complexity |
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Thanks. No hurries. It does add extra complexity. Also I think the performance issue on json-schema-validator is probably fixed/mitigated by networknt/json-schema-validator#1217 - need to be confirmed. |
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Add optional
--use-additional-propertiesflag to command line, to useadditionalPropertiesinstead ofunevaluatedProperties(which has a known performance regression issue with networknt json-schema-validator 2.0.0)Note that the size of the generated schema will grow with this option, as we have to repeat the inherited property list for every classes (see snippets in #117 (comment)).
To fix #60 as reported by @goneall