Basic json-schema generator based on Go types, for easy interchange of Go strcutures across languages.
The recommended way to install go-jsonschema-generator
go get github.com/mcuadros/go-jsonschema-generator
A basic example:
package main
import (
"fmt"
"github.com/mcuadros/go-jsonschema-generator"
)
type ExampleBasic struct {
Foo bool `json:"foo"`
Bar string `json:",omitempty"`
Qux int8
Baz []string
}
func main() {
s := &jsonschema.Document{}
s.Read(&ExampleBasic{})
fmt.Println(s)
}
{
"$schema": "http://json-schema.org/schema#",
"type": "object",
"properties": {
"Bar": {
"type": "string"
},
"Baz": {
"type": "array",
"items": {
"type": "string"
}
},
"Qux": {
"type": "integer"
},
"foo": {
"type": "bool"
}
},
"required": [
"foo",
"Qux",
"Baz"
]
}
MIT, see LICENSE