json-schema-generator

command module
v0.0.0-...-9560c5d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2018 License: Apache-2.0 Imports: 1 Imported by: 0

README

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.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL