Skip to content

frederikgoebel/go-json-schema-generator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-json-schema-generator

Generate JSON Schema out of Golang schema

Usage

First install the package

go get -u github.com/urakozz/go-json-schema-generator

Then create your generator file (see Example folder)

package main

import (
	"fmt"
	"github.com/urakozz/go-json-schema-generator"
)

type Domain struct {
	Data string `json:"data"`
}

func main(){
	fmt.Println(generator.Generate(&Domain{}))
}

Supported tags

  • required:"true" - field will be marked as required
  • description:"description" - description will be added

Expected behaviour

If struct field is pointer to the primitive type, then schema will allow this typa and null. E.g.:

type Domain struct {
	NullableData *string `json:"nullableData"`
}

Output

{
    "$schema": "http://json-schema.org/schema#",
    "type": "object",
    "properties": {
        "nullableData": {
            "anyOf": [
                {
                    "type": "string"
                },
                {
                    "type": "null"
                }
            ]
        }
    }
}

About

Generate JSON Schema out of Golang schema

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%