Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 5 days 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 (about 10 years ago)
- Default Branch: master
- Last Pushed: 2022-03-28T06:57:23.000Z (over 2 years ago)
- Last Synced: 2024-12-15T15:11:41.383Z (10 days 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: 121
- Watchers: 5
- Forks: 30
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
go-jsonschema-generator [![Build Status](https://img.shields.io/github/workflow/status/mcuadros/go-jsonschema-generator/Test.svg)](https://github.com/mcuadros/go-jsonschema-generator/actions) [![GoDoc](http://godoc.org/github.com/mcuadros/go-jsonschema-generator?status.png)](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 mainimport (
"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)