Skip to content

Getting Started

Install
go get github.com/tylergannon/go-gen-jsonschema

Create or edit a Go file in your package. Register a type and run codegen.

example/user.go
package example
//go:generate gen-jsonschema
import (
"encoding/json"
jsonschema "github.com/tylergannon/go-gen-jsonschema"
)
type User struct {
ID int `json:"id"`
Name string `json:"name"`
}
// Stub method. The generator will replace this implementation.
func (User) Schema() json.RawMessage { panic("not implemented") }
var (
_ = jsonschema.NewJSONSchemaMethod(User.Schema)
)
Codegen
go generate ./...

This writes JSON Schema files to ./jsonschema and generates jsonschema_gen.go.

  • Read the Spec for enums, interfaces, and providers.
  • Browse the Examples for working samples.
  • See API Reference for the full exported API.