Carvel Logo

Schema Validations Cheat Sheet

(For a more detailed guide, see Writing Schema Validations.)

Use CaseSyntax

Required string

usage: Using the empty/zero value
reference: min_len=

#@schema/validation min_len=1
username: ""

Required integer

usage: Using the empty/zero value
reference: min=

#@schema/validation min=1
replicas: 0

Required array

usage: Using the empty/zero value
reference: min_len=

#@schema/validation min_len=1 
responseTypes:
- ""

Required map

usage: mark as “nullable” and “not_null”
reference: @schema/nullable and not_null=

#@schema/nullable
#@schema/validation not_null=True
credential:
  name: ""
  cloud: ""

Ensure string minimum length

reference: min_len=

#@schema/validation min_len=8
password: ""

Ensure string exact length

#@schema/validation min_len=8, max_len=8
password: ""

Ensure a min value

#@schema/validation min=3
replicas: 5

Ensure a max value

#@schema/validation max=5
replicas: 3

Ensure a value between min and max

#@schema/validation min=1, max=65535
port: 1024

Enumeration

usage: enumerations
reference: one_of=

#@schema/validation one_of=["aws", "azure", "vsphere"]
provider: ""

Exactly one is specified

usage: mutually exclusive config
reference: one_not_null=

#@schema/validation one_not_null=["oidc", "ldap"]
config:
  #@schema/nullable
  oidc:
    client_id: “”
  #@schema/nullable
  ldap:
    host: “”

Conditionally run validations

usage: conditional validations
reference: @schema/validation ... when=

#@data/values-schema
---
service:
  type: LoadBalancer
  #@schema/validation min_len=1, when=lambda _, ctx: ctx.parent["type"] == "LoadBalancer"
  name: ""

Custom description of valid value

usage: writing custom rules
reference: @ytt:assert

#@ load("@ytt:assert", "assert")

#@schema/validation ("a non-blank name", assert.min_len(1))
username: ""

Disable validations flag

$ ytt ... --dangerous-data-values-disable-validation


(Help improve our docs: edit this page on GitHub)