2

I have 2 properties I want to list out which are os_type and os_version.

os_type would be an enum with several values like windows, linux, etc.

based on the os_type, os_version values would be different enum values.

like for windows, os_version would be 7,8,10

for linux, os_version would be ubuntu, fedora etc

How can I do this with a json schema where os_version is dependent on the os_type and different enum values for os_version are displayed based on the os_type?

This is my current code snippet, not quite working.

{
    "namespace": "MetadataOSVersion",
    "display_name": "Company Metadata: OS Version",
    "description": "Company Metadata: OS Version",
    "visibility": "public",
    "protected": true,
    "objects": [
        {
            "name": "os_type",
            "description": "os_type",
            "properties": {
                "os_type":
                {
                    "title": "os_type",
                    "description": "os_type",
                    "type": "string",
                    "enum": ["Linux", "Windows"]
                },
                "os_version":
                {
                    "title": "os_version",
                    "description": "os_version",
                    "type": "string",
                    "required": ["os_type"],
                    "oneOf": [
                        {{"os_type": {"enum": ["Windows"], "enum": ["7", "8", "10"]}}},
                        {{"os_type": {"enum": ["Linux"], "enum": ["Ubuntu", "Fedora"]}}}
                    ]
                }
            }
       }
        ]

}
hifx
  • 21
  • 1
  • 3
  • Possible duplicate of [JsonSchema: Validate type based on value of another property](https://stackoverflow.com/questions/49784760/jsonschema-validate-type-based-on-value-of-another-property) – Relequestual May 01 '18 at 08:28
  • It's not especially obvious and there aren't many resource that explain this. Especially with newer versions of JSON Schema. We also have a Slack channel you need any additional help or want to ask any questions which are more discussion based. – Relequestual May 01 '18 at 09:26
  • 1
    Possible duplicate of [jsonSchema attribute conditionally required](https://stackoverflow.com/questions/38717933/jsonschema-attribute-conditionally-required) – Jason Desrosiers May 06 '18 at 04:18
  • Duplicate of https://stackoverflow.com/questions/50228218/json-schema-dependencies-enum-content-depends-on-choice-from-another-enum/50323425 – vearutop May 14 '18 at 05:14

0 Answers0