https://github.com/mcuadros/go-jsonschema-generator
json-schemas generator based on Go types
https://github.com/mcuadros/go-jsonschema-generator
go json-schema jsonschema-generator
Last synced: 8 months ago
JSON representation
json-schemas generator based on Go types
- Host: GitHub
- URL: https://github.com/mcuadros/go-jsonschema-generator
- Owner: mcuadros
- License: mit
- Created: 2014-11-21T11:08:26.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2022-03-28T06:57:23.000Z (about 4 years ago)
- Last Synced: 2025-10-21T02:54:21.437Z (8 months ago)
- Topics: go, json-schema, jsonschema-generator
- Language: Go
- Homepage: https://pkg.go.dev/github.com/mcuadros/go-jsonschema-generator
- Size: 17.6 KB
- Stars: 120
- Watchers: 3
- Forks: 30
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
go-jsonschema-generator [](https://github.com/mcuadros/go-jsonschema-generator/actions) [](https://pkg.go.dev/github.com/mcuadros/go-jsonschema-generator)
==============================
Basic [json-schema](http://json-schema.org/) generator based on Go types, for easy interchange of Go structures across languages.
Installation
------------
The recommended way to install go-jsonschema-generator
```
go get github.com/mcuadros/go-jsonschema-generator
```
Examples
--------
A basic example:
```go
package main
import (
"fmt"
"github.com/mcuadros/go-jsonschema-generator"
)
type EmbeddedType struct {
Zoo string
}
type Item struct {
Value string
}
type ExampleBasic struct {
Foo bool `json:"foo"`
Bar string `json:",omitempty"`
Qux int8
Baz []string
EmbeddedType
List []Item
}
func main() {
s := &jsonschema.Document{}
s.Read(&ExampleBasic{})
fmt.Println(s)
}
```
```json
{
"$schema": "http://json-schema.org/schema#",
"type": "object",
"properties": {
"Bar": {
"type": "string"
},
"Baz": {
"type": "array",
"items": {
"type": "string"
}
},
"List": {
"type": "array",
"items": {
"type": "object",
"properties": {
"Value": {
"type": "string"
}
},
"required": [
"Value"
]
}
},
"Qux": {
"type": "integer"
},
"Zoo": {
"type": "string"
},
"foo": {
"type": "boolean"
}
},
"required": [
"foo",
"Qux",
"Baz",
"Zoo",
"List"
]
}
```
License
-------
MIT, see [LICENSE](LICENSE)