Skip to content

Support JSON Schema conditional validation (if/then/else) for required fields #23

Open

Description

Today cozyvalues-gen can mark a field as required only unconditionally (via @field {type} name without brackets) or optional (@field {type} [name]). There is no way to express "field X is required only when field Y has value Z" in the generated values.schema.json, even though JSON Schema Draft 7 supports this via if/then/else or allOf + dependencies.

Use case. In chart packages/extra/etcd (cozystack/cozystack), the fields backup.destinationPath, backup.endpointURL, backup.s3AccessKey, and backup.s3SecretKey are required when backup.enabled: true and should be left empty otherwise. Render-time validation with the Helm required function is already in place, but the dashboard would give users earlier, field-level feedback if the generated schema could express the condition.

Proposed annotation (sketch, open to bikeshedding):

## @typedef {struct} Backup - ...
## @field {bool} [enabled] - ...
## @field {string} [destinationPath] - ...
## @requiredIf enabled=true destinationPath endpointURL s3AccessKey s3SecretKey

which would emit:

"backup": {
  "properties": {...},
  "if":   {"properties": {"enabled": {"const": true}}},
  "then": {"required": ["destinationPath","endpointURL","s3AccessKey","s3SecretKey"]}
}

Context: cozystack/cozystack#2428 (review thread cozystack/cozystack#2428 (comment)).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions