Skip to content

[CDX2.0]: have no "other" enums values where alternative, arbitrary strings are allowed #961

Description

@jkowalleck

Describe the defect

CycloneDX 2.0 has enums for many things.
Some have the case "other".
And alternatively, same enum values are open, arbitrary string.

For example

When the property can be either an enums or an arbitrary string, there is no need go an emum value "other".

Goal

  • Have no "other", when the enums is non-exclusive.
  • At best, have them forward-compatible

Additional context

Add any other context about the problem here.

possible solution A

this is thing we are already using in other places.

  • have it either a string - with enum values
  • or have it an object with name and description

like here

"oneOf": [
{
"title": "Pre-Defined Kind",
"type": "string",
"enum": [
"software-system",
"hardware-system",
"service-account",
"machine-identity",
"automation",
"agent",
"bot",
"oracle",
"smart-contract",
"device",
"robot"
],
"meta:enum": {
"software-system": "Application, service, or platform that performs actions as itself.",
"hardware-system": "Physical device or appliance that performs actions. Includes vehicles, drones, satellites, medical devices, network equipment, and industrial controllers unless a more specific kind applies.",
"service-account": "Non-human identity used by automation to authenticate.",
"machine-identity": "Cryptographic identity such as a certificate principal or workload identity.",
"automation": "Pipeline, job, or scheduled task that performs actions deterministically.",
"agent": "Autonomous or semi-autonomous agent that can plan and execute. Includes AI agents.",
"bot": "Scripted automation that interacts with an interface. Includes chatbots, robotic process automation bots, and scraping bots.",
"oracle": "External data feed or oracle, including blockchain oracles that bridge off-chain data into on-chain systems.",
"smart-contract": "On-chain program that executes deterministically.",
"device": "Physical end user device such as a phone or IoT device acting as a party in its own right.",
"robot": "Physical robot or autonomous mechanical system. For software-only counterparts, see `bot`, `agent`, or `automation`."
}
},
{
"title": "Custom Kind",
"type": "object",
"required": [ "name" ],
"additionalProperties": false,
"properties": {
"name": {
"type": "string",
"minLength": 1,
"title": "Name",
"description": "The name of the custom kind."
},
"description": {
"type": "string",
"title": "Description",
"description": "A description of the custom kind."
}
}
}
]

{
  "type": "object",
  "properties": {
    "foo": {
      "oneOf": [
        {
          "title": "Pre-Defined Foo",
          "type": "string",
          "enum": [
            "well-known-1",
            "well-known-2",
            "well-known-3"
          ],
          "meta:enum": {
            "well-known-1": "the description what this means",
            "well-known-2": "the description what this other value means" ,
            "well-known-3": "..."
          }
        },
        {
          "title": "Custom Foo",
          "type": "object",
          "required": [ "name" ],
          "additionalProperties": false,
          "properties": {
            "name": {
              "type": "string",
              "minLength": 1,
              "title": "Name",
              "description": "The name of the custom foo."
            },
            "description": {
              "type": "string",
              "title": "Description",
              "description": "A description of the custom foo."
            }
          }
        }
      ]
    }
  }
}

possible solution B

{
  "type": "object",
  "properties": {
    "foo": {
      "type": "string",
      "anyOf": [
        {
          "$comment": "well-known values",
          "enum": [
            "well-known-1",
            "well-known-2",
            "well-known-3"
          ],
          "meta:enum": {
            "well-known-1": "the description what this means",
            "well-known-2": "the description what this other value means" ,
            "well-known-3": "..."
          }
        },
        {
          "$comment": "custom value",
          "type": "string",
          "minLength": 1
        }
      ]
    }
  }
}

Preferably,
we might even go with a prefix on the "custom"("other"), tho prevent collisions when adding new values with well-defined values

{
  "type": "object",
  "properties": {
    "foo": {
      "type": "string",
      "anyOf": [
        {
          "$comment": "well-known values",
          "enum": [
            "well-known-1",
            "well-known-2",
            "well-known-3"
          ],
          "meta:enum": {
            "well-known-1": "the description what this means",
            "well-known-2": "the description what this other value means" ,
            "well-known-3": "..."
          }
        },
        {
          "$comment": "custom - prefixed with 'custom: '",
          "type": "string"
          "pattern": "^custom: (.+)$"
        }
      ]
    }
  }
}

possible solution C

... to be discussed ...
maybe something like

{
  "type": "object",
  "properties": {
    "category": { "type": "string", "enum": ["red", "green", "blue", "custom"] },
    "categoryCustom": { "type": "string", "minLength": 1 }
  },
  "required": ["category"],
  "allOf": [
    {
      "if": { "properties": { "category": { "const": "custom" } }, "required": ["category"] },
      "then": { "required": ["categoryCustom"] },
      "else": { "not": { "required": ["categoryCustom"] } }
    }
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions