jsondoc

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2019 License: MIT Imports: 8 Imported by: 2

README

go-json-doc

Build Status codecov

Go documentation generator for JSON structs.

go-json-doc uses reflection to generate JSON schemas for go structs.

Usage

API documentation can be read at Godoc.

doc, err := jsondoc.NewGlossary().Describe(new(struct{
  Name string
  Age int
  Occupation `json:"Job"`
}))

fmt.Println(doc)
// {
//   "Name": "<string>",
//   "Age": "<string>",
//   "Job": "<string>"
// }

A more complete example can be found in the examples directory.

Contribute

PRs accepted.

Contributors

  • Steven Allen (@stebalien)
  • Initial concept by Hector Sanjuan (@hsanjuan)

License

MIT © Steven Allen

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array []interface{}

Array is a helper type for constructing JSON arrays.

type Glossary

type Glossary struct {
	// contains filtered or unexported fields
}

Glossary describes the set of types used in the structures to be described.

This type memoizes and is NOT type-safe.

func NewGlossary

func NewGlossary() *Glossary

NewGlossary creates a new glossary. In addition to th

func (*Glossary) Clone

func (d *Glossary) Clone() *Glossary

Clone clones the glossary. The cloned glossary can be safely used concurrently with the original glossary.

func (*Glossary) Describe

func (d *Glossary) Describe(thing interface{}) (string, error)

Describe returns a description for the given type.

func (*Glossary) WithName

func (d *Glossary) WithName(thing interface{}, name string) *Glossary

WithName names the 'thing's type.

For example, one can name all instances of MyStruct as "<my-struct>" with:

glossary.Name(new(MyStruct), "my-struct")

func (*Glossary) WithSchema

func (d *Glossary) WithSchema(thing interface{}, schema interface{}) *Glossary

WithSchema describes 'thing's type with the given schema. The 'schema' must marshal to JSON.

This can be used to give types that implement custom json marshallers accurate descriptions.

type Object

type Object map[string]interface{}

Object is a helper type for constructing JSON objects.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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