Question: intent of schema license definition required properties #493
-
I have a clarification question about the intent of the required properties in the The license definition says that only one of This validates against the schema, but does it match the intended usage of the property? "licenses": [
{
"license": {
"id": "Apache-2.0",
"name": "MIT"
}
}
] Or might it make more sense to define the schema such that only one of Schema example "license": {
"type": "object",
"oneOf": [
{
"required": ["id"],
"properties": {
"id": {
"$ref": "spdx.schema.json",
"description": "A valid SPDX license ID"
}
}
},
{
"required": ["name"],
"properties": {
"name": {
"type": "string",
"description": "If SPDX does not define the license used, this field may be used to provide the license name"
}
}
}
],
"additionalProperties": false,
"properties": {
"bom-ref": {
"$ref": "#/definitions/refType",
"description": "An optional identifier which can be used to reference the license elsewhere in the BOM. Every bom-ref MUST be unique within the BOM.\nValue SHOULD not start with the BOM-Link intro 'urn:cdx:' to avoid conflicts with BOM-Links."
},
// ...
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
The intention is to have exactly one of The JSON schema: specification/schema/bom-1.6.schema.json Lines 1232 to 1258 in 55343ba For comparison, see XML schema: specification/schema/bom-1.6.xsd Lines 761 to 772 in 55343ba
Nope, it does not. maybe your json schema validator is implemented wrong? JSON is valid against more than one schema from 'oneOf' - therefore, the data set you provided is invalid. data used for testing the JSON schema
could be used on https://www.jsonschemavalidator.net/ schema cutout {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"title": "License",
"oneOf": [
{
"required": ["id"]
},
{
"required": ["name"]
}
],
"additionalProperties": false,
"properties": {
"id": { },
"name": { },
}
} example data set {
"id": true,
"name": true
} |
Beta Was this translation helpful? Give feedback.
-
Additional technical detail:
We found this to be not-working. |
Beta Was this translation helpful? Give feedback.
The intention is to have exactly one of
name
orid
present.And that is exactly what the current JSON schema does.
The JSON schema:
specification/schema/bom-1.6.schema.json
Lines 1232 to 1258 in 55343ba