jsonsch

package
v0.0.0-...-d807e2c Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitSchema

func InitSchema(s Schema, doPopLists, doRandom bool) (map[string]interface{}, error)

InitSchema is the only exposed method in this file InitSchema is a method on Schema which returns an instance of the schema.

InitSchema assumes all $ref fields are already either 1) resolved and replaced by a network request 2) replaced by an empty object

func ReplaceRefs

func ReplaceRefs(data map[string]interface{}, doSkipRefs bool) error

func SerializeGraphQL

func SerializeGraphQL(s Schema, w io.Writer) error

func SerializeSchema

func SerializeSchema(s Schema, w io.Writer, doPretty bool) error

func ToGraphQLSchema

func ToGraphQLSchema(s Schema) (*graphqlsch.Schema, error)

func ToGraphQLTypes

func ToGraphQLTypes(rootSchema Schema, rootName string) ([]graphqlsch.Type, error)

Types

type ArraySchema

type ArraySchema struct {
	Type  Type        `json:"type"`
	Items interface{} `json:"items"`
}

func NewArray

func NewArray(items interface{}) ArraySchema

func TodoRenameThisFunctionLmao

func TodoRenameThisFunctionLmao(data []interface{}, params *FromExampleParams) (ArraySchema, error)

type FromExampleParams

type FromExampleParams struct {
	DoOmitReq     bool
	DoMakeReq     bool
	EmptyArraysAs string
	NullAs        string
}

type Primitive

type Primitive struct {
	Type        Type   `json:"type"`
	Description string `json:"description,omitempty"`
}

func NewBoolean

func NewBoolean() Primitive

func NewNull

func NewNull(params *FromExampleParams) Primitive

func NewNumber

func NewNumber() Primitive

func NewString

func NewString() Primitive

type Schema

type Schema interface {
	GetSchemaField() string
	SetSchemaField(string)
	GetTitle() string
	SetTitle(string)
	GetType() Type
	SetType(Type)
	GetDescription() string
	SetDescription(string)
	GetProperties() map[string]interface{}
	SetProperties(map[string]interface{})
	SetProperty(string, interface{})
	GetRequired() []string
	SetRequired([]string)
}

This only exists because we need two different types for the same exact struct---a struct representing JSON schema---where the struct tags of one of the types are different from the struct tags of the other type. This way, we can omit the `required` field during serialization.

func FromExample

func FromExample(ex *example.Example, params *FromExampleParams) (Schema, error)

func FromSchema

func FromSchema(data map[string]interface{}, doSkipRefs bool) (Schema, error)

type SchemaInclReq

type SchemaInclReq struct {
	SchemaField string                 `json:"$schema,omitempty"`
	Title       string                 `json:"title"`
	Type        Type                   `json:"type"`
	Description string                 `json:"description,omitempty"`
	Properties  map[string]interface{} `json:"properties"`
	Required    []string               `json:"required"`
}

func NewInclReq

func NewInclReq() *SchemaInclReq

func (*SchemaInclReq) GetDescription

func (s *SchemaInclReq) GetDescription() string

func (*SchemaInclReq) GetProperties

func (s *SchemaInclReq) GetProperties() map[string]interface{}

func (*SchemaInclReq) GetRequired

func (s *SchemaInclReq) GetRequired() []string

func (*SchemaInclReq) GetSchemaField

func (s *SchemaInclReq) GetSchemaField() string

func (*SchemaInclReq) GetTitle

func (s *SchemaInclReq) GetTitle() string

func (*SchemaInclReq) GetType

func (s *SchemaInclReq) GetType() Type

func (*SchemaInclReq) SetDescription

func (s *SchemaInclReq) SetDescription(d string)

func (*SchemaInclReq) SetProperties

func (s *SchemaInclReq) SetProperties(ps map[string]interface{})

func (*SchemaInclReq) SetProperty

func (s *SchemaInclReq) SetProperty(k string, v interface{})

func (*SchemaInclReq) SetRequired

func (s *SchemaInclReq) SetRequired(r []string)

func (*SchemaInclReq) SetSchemaField

func (s *SchemaInclReq) SetSchemaField(sf string)

func (*SchemaInclReq) SetTitle

func (s *SchemaInclReq) SetTitle(t string)

func (*SchemaInclReq) SetType

func (s *SchemaInclReq) SetType(t Type)

type SchemaOmitReq

type SchemaOmitReq struct {
	SchemaField string                 `json:"$schema,omitempty"`
	Title       string                 `json:"title"`
	Type        Type                   `json:"type"`
	Description string                 `json:"description,omitempty"`
	Properties  map[string]interface{} `json:"properties"`
	Required    []string               `json:"required,omitempty"`
}

func NewOmitReq

func NewOmitReq() *SchemaOmitReq

func (*SchemaOmitReq) GetDescription

func (s *SchemaOmitReq) GetDescription() string

func (*SchemaOmitReq) GetProperties

func (s *SchemaOmitReq) GetProperties() map[string]interface{}

func (*SchemaOmitReq) GetRequired

func (s *SchemaOmitReq) GetRequired() []string

func (*SchemaOmitReq) GetSchemaField

func (s *SchemaOmitReq) GetSchemaField() string

func (*SchemaOmitReq) GetTitle

func (s *SchemaOmitReq) GetTitle() string

func (*SchemaOmitReq) GetType

func (s *SchemaOmitReq) GetType() Type

func (*SchemaOmitReq) SetDescription

func (s *SchemaOmitReq) SetDescription(d string)

func (*SchemaOmitReq) SetProperties

func (s *SchemaOmitReq) SetProperties(ps map[string]interface{})

func (*SchemaOmitReq) SetProperty

func (s *SchemaOmitReq) SetProperty(k string, v interface{})

func (*SchemaOmitReq) SetRequired

func (s *SchemaOmitReq) SetRequired(r []string)

func (*SchemaOmitReq) SetSchemaField

func (s *SchemaOmitReq) SetSchemaField(sf string)

func (*SchemaOmitReq) SetTitle

func (s *SchemaOmitReq) SetTitle(t string)

func (*SchemaOmitReq) SetType

func (s *SchemaOmitReq) SetType(t Type)

type Type

type Type string
const (
	Object  Type = "object"
	Boolean Type = "boolean"
	Array   Type = "array"
	Number  Type = "number"
	Integer Type = "integer"
	String  Type = "string"
	Null    Type = "null"
)

Jump to

Keyboard shortcuts

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