OpenAPI to JSON Schema conversion
Kubeconform uses JSON schemas to validate Kubernetes resources. For custom resources, the CustomResourceDefinition first needs to be converted to JSON Schema. A script is provided to convert these CustomResourceDefinitions to JSON schema. Here is an example how to use it:
#!/bin/bash
$ ./scripts/openapi2jsonschema.py https://raw.githubusercontent.com/aws/amazon-sagemaker-operator-for-k8s/master/config/crd/bases/sagemaker.aws.amazon.com_trainingjobs.yaml
JSON schema written to trainingjob_v1.json
The FILENAME_FORMAT
environment variable can be used to change the output file name (Available variables: kind
, group
, version
) (Default: {kind}_{version}
).
$ export FILENAME_FORMAT='{kind}-{group}-{version}'
$ ./scripts/openapi2jsonschema.py https://raw.githubusercontent.com/aws/amazon-sagemaker-operator-for-k8s/master/config/crd/bases/sagemaker.aws.amazon.com_trainingjobs.yaml
JSON schema written to trainingjob-sagemaker-v1.json
Some CRD schemas do not have explicit validation for fields implicitly validated by the Kubernetes API like apiVersion
, kind
, and metadata
, thus additional properties are allowed at the root of the JSON schema by default, if this is not desired the DENY_ROOT_ADDITIONAL_PROPERTIES
environment variable can be set to any non-empty value.