Skip to content

kedgeproject/json-schema-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create JSONSchema for Kedge

Creating OpenAPI

This will create OpenAPI configuration for kedge, but make sure you have Kubernetes Swagger OpenAPI schema swagger.json and Kedge types.go downloaded locally. For detailed steps see manual steps.

make install
kedge-jsonschema

Creating JSONSchema

Doing it the easy way

Note: Needs docker to be installed on your machine locally.

make generate-config

The docker image used as base for creating this image has openapi2jsonschema installed in it. Creating a docker image makes it easier to reduce the steps needed to do things manually for various tools.

Doing it the hard way

Let's download the Kubernetes OpenAPI schema

cd $GOPATH/src/github.com/kedgeproject/json-schema-generator
curl -O https://raw.githubusercontent.com/kubernetes/kubernetes/$(curl https://raw.githubusercontent.com/kedgeproject/json-schema-generator/master/scripts/k8s-release)/api/openapi-spec/swagger.json

Also we need to download the Kedge types.go file

curl -O https://raw.githubusercontent.com/kedgeproject/kedge/master/pkg/spec/types.go

Let's build the binary that generates OpenAPI schema for Kedge

make install

Generate OpenAPI schema for Kedge and save it in output.json

schemagen > output.json

This is just half done, now install a tool called openapi2jsonschema. It will read the OpenAPI specification stored in output.json and generate JSON Specification for Kedge.

Once installed run openapi2jsonschema

mkdir -p schema
openapi2jsonschema --strict output.json -o schema/ --stand-alone

Now all the JSONSchemas are generated in schema directory. The one that is most important to us is deploymentspecmod.json.

Protip: To avoid all these manual steps do it the easy way.

Validating against schema

Install jsonschema tool locally

jsonschema -F "{error.message}" -i ./example/db.json ./schema/deploymentspecmod.json

Since the input file db.json has deployment so we are using this deploymentspecmod.json to validate. If the controller is different we will have to use a different file.

The file deploymentspecmod.json has schema for validating kedge. The above file db.json is taken from kedge repo example.

JSONSchema generation process

Read more about the JSONSchema generation process in conversion.md.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published