json-schema generator based on Go types
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
}
func main() {
j := &jsonschema.JSONSchema{}
j.Load(&ExampleBasic{})
fmt.Println(j)
}
{
"type": "object",
"properties": {
"Bar": {
"type": "string"
},
"Qux": {
"type": "integer"
},
"foo": {
"type": "bool"
}
},
"required": [
"foo",
"Qux"
]
}
MIT, see LICENSE