Skip to content

Latest commit

 

History

History
 
 

docs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Annotations from comments

JSON schema is partially implemented in this tool. It uses line comments to add annotations for the schema because head comments are frequently used by humans and tools like helm-docs. Multiple annotations can be added to a single line sepparated by semi-colon. For example:

nameOverride: "myapp" # @schema maxLength:10;patter:^[a-z]+$

This will generate following schema:

"nameOverride": {
    "maxLength": 10,
    "type": "string"
}

The following annotations are supported:

Validation Keywords for Any Instance Type

Type

The type keyword is used to restrict a value to a specific primitive type. There are several possible values for type:

  • string
  • number
  • integer
  • boolean
  • object
  • array
  • null

Multiple types

Default behaviour returns always a string unless annotation is used. In that case, it returns array of strings. Useful for keys without any value declared for documentation purposes. section 6.1.1

# -- (int) replica count
replicaCount: # @schema type:[integer, null]
"replicaCount": {
    "type": [
        "integer",
        "null"
    ]
}

Another way to use this is to define type when using anchors and aliases in yaml. See discussion #28 for more details.

app: &app
  settings:
    namespace:
      - *app # @schema type:[string]
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "properties": {
        "app": {
            "properties": {
                "settings": {
                    "properties": {
                        "namespace": {
                            "items": {
                                "type": [
                                    "string"
                                ]
                            },
                            "type": "array"
                        }
                    },
                    "type": "object"
                }
            },
            "type": "object"
        }
    },
    "type": "object"
}

Enum

Always returns array of strings. Special case is null where instead of string, it is treated as valid inpput type. section 6.1.2

service: ClusterIP # @schema enum:[ClusterIP, LoadBalancer, null]
"service": {
    "enum": [
        "ClusterIP",
        "LoadBalancer",
        null
    ],
    "type": "string"
}

Strings

maxLength

Non-negative integer. section 6.3.1

nameOverride: "myapp" # @schema maxLength:10

This will generate following schema:

"nameOverride": {
    "maxLength": 10,
    "type": "string"
}

minLength

Non-negative integer. section 6.3.1

nameOverride: "myapp" # @schema minLength:3

This will generate following schema:

"nameOverride": {
    "minLength": 3,
    "type": "string"
}

pattern

String that is valid regular expression, according to the ECMA-262 regular expression dialect. section 6.3.3

nameOverride: "myapp" # @schema patter:^[a-z]+$

This will generate following schema:

"nameOverride": {
    "type": "string"
}

Numbers

multipleOf

Number greater than 0. section 6.2.1

replicas: 2 # @schema multipleOf:2
"replicas": {
    "multipleOf": 2,
    "type": "integer"
}

maximum

Number. section 6.2.2

replicas: 2 # @schema maximum:10
"replicas": {
    "maximum": 10,
    "type": "integer"
}

minimum

Number. section 6.2.4

replicas: 5 # @schema minimum:2
"replicas": {
    "minimum": 2,
    "type": "integer"
}

Arrays

maxItems

Non-negative integer. section 6.4.1

dummyList: # @schema maxItems:5
  - "item1"
  - "item2"
  - "item3"
"dummyList": {
    "items": {
        "type": "string"
    },
    "maxItems": 5,
    "type": "array"
}

minItems

Non-negative integer. section 6.4.2

dummyList: # @schema minItems:2
  - "item1"
  - "item2"
  - "item3"
"dummyList": {
    "items": {
        "type": "string"
    },
    "minItems": 2,
    "type": "array"
}

uniqueItems

Boolean. section 6.4.3

dummyList: # @schema uniqueItems:true
  - "item1"
  - "item2"
  - "item3"
"dummyList": {
    "items": {
        "type": "string"
    },
    "type": "array",
    "uniqueItems": true
}

Objects

maxProperties

Non-negative integer. section 6.5.1

nodeSelector: # @schema maxProperties:10
  kubernetes.io/hostname: "my-node"
"nodeSelector": {
    "maxProperties": 10,
    "properties": {
        "kubernetes.io/hostname": {
            "type": "string"
        }
    },
    "type": "object"
}

minProperties

Non-negative integer. section 6.5.2

nodeSelector: # @schema minProperties:1
  kubernetes.io/hostname: "my-node"
"nodeSelector": {
    "minProperties": 1,
    "properties": {
        "kubernetes.io/hostname": {
            "type": "string"
        }
    },
    "type": "object"
}

required

Array of unique strings appened to the parent node. section 6.5.3

image:
  repository: "nginx" # @schema required:true
  tag: "latest" # @schema required:true
  imagePullPolicy: "IfNotPresent"
"image": {
    "properties": {
        "imagePullPolicy": {
            "type": "string"
        },
        "repository": {
            "type": "string"
        },
        "tag": {
            "type": "string"
        }
    },
    "required": [
        "repository",
        "tag"
    ],
    "type": "object"
}

Meta-Data Annotations

title

String. section 9.1

fullnameOverride: bar # @schema title: My title
"fullnameOverride": {
    "title": "My title",
    "type": "string"
},

readOnly

Boolean. section 9.4

image:
  tag: latest # @schema readOnly: true
"image": {
    "properties": {
        "tag": {
            "readOnly": true,
            "type": "string"
        }
    },
    "type": "object"
}