jsonschema

package module
v0.0.0-...-ba7a369 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2020 License: MIT Imports: 3 Imported by: 72

README

go-jsonschema-generator Build Status GoDoc

Basic json-schema 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:

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)
}
{
    "$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

Documentation

Overview

Basic json-schema generator based on Go types, for easy interchange of Go structures between diferent languages.

Index

Constants

View Source
const DEFAULT_SCHEMA = "http://json-schema.org/schema#"

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document struct {
	Schema string `json:"$schema,omitempty"`
	// contains filtered or unexported fields
}

func (*Document) Marshal

func (d *Document) Marshal() ([]byte, error)

Marshal returns the JSON encoding of the Document

func (*Document) Read

func (d *Document) Read(variable interface{})

Reads the variable structure into the JSON-Schema Document

func (*Document) String

func (d *Document) String() string

String return the JSON encoding of the Document as a string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL