parser

package
v0.0.0-...-8a85022 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const MethodSignatureTemplate = `` /* 277-byte string literal not displayed */
View Source
const MethodTemplate = `` /* 211-byte string literal not displayed */

Variables

View Source
var (
	ErrNotRegistred = errors.New("This Handler is not registered.")
)

Functions

This section is empty.

Types

type Component

type Component interface {
	Name() string
}

type Field

type Field interface {
	Component
	WithFieldTag(string) Field
	FieldTag() string
	WithReference(bool) Field
}

type HandleSchemaFunc

type HandleSchemaFunc func(*SchemaContext, Root, string, *jsonschema.Schema) (Component, error)

type HandlerRegistry

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

func NewHandlerRegistry

func NewHandlerRegistry() *HandlerRegistry

func (HandlerRegistry) RegisterHandler

func (s HandlerRegistry) RegisterHandler(kind Kind, handler HandleSchemaFunc)

func (HandlerRegistry) ResolveHandler

func (s HandlerRegistry) ResolveHandler(kind Kind) HandleSchemaFunc

type Kind

type Kind int
const (
	Boolean Kind = iota
	Enum
	String
	Interger
	Number
	Array
	Reference
	OneOf
	AnyOf
	AllOf
	Object
	Document
	Invalid
)

func (Kind) String

func (s Kind) String() string

type Method

type Method struct {
	Comment  string
	Receiver string
	*MethodSignature
	Body string
}

func NewMethodFromSignature

func NewMethodFromSignature(receiver string, methodSignature *MethodSignature) *Method

func (*Method) WithInputs

func (s *Method) WithInputs(inputs ...*Parameter) *Method

func (*Method) WithOutputs

func (s *Method) WithOutputs(outputs ...*Parameter) *Method

type MethodSignature

type MethodSignature struct {
	Name    string
	Inputs  []*Parameter
	Outputs []*Parameter
}

func NewMethodSignature

func NewMethodSignature(name string) *MethodSignature

func (*MethodSignature) WithInputs

func (s *MethodSignature) WithInputs(inputs ...*Parameter) *MethodSignature

func (*MethodSignature) WithOutputs

func (s *MethodSignature) WithOutputs(outputs ...*Parameter) *MethodSignature

type Parameter

type Parameter struct {
	Name string
	Type string
}

func NewParameter

func NewParameter(name, typename string) *Parameter

type Parser

type Parser interface {
	Parse(schemas map[jsonschema.ID]*jsonschema.Schema, references map[jsonschema.ID]*jsonschema.Schema) (map[jsonschema.ID]Component, error)
}

func NewParser

func NewParser(packageName string, registry *HandlerRegistry) Parser

type Process

type Process func(schema *jsonschema.Schema) (Component, error)

type Receiver

type Receiver interface {
	Field
	WithMethods(methods ...*Method)
}

type Resolve

type Resolve func(schema *jsonschema.Schema, document Root) HandleSchemaFunc

type Root

type Root interface {
	Component
	Globals() map[string]Component
	AddImport(value string)
}

type SchemaContext

type SchemaContext struct {
	PackageName string
	// contains filtered or unexported fields
}

SchemaContext is the collection of all schema's being processed

func NewSchemaContext

func NewSchemaContext(packageName string, resolve Resolve, references map[jsonschema.ID]*jsonschema.Schema) *SchemaContext

NewSchemaContext return's a SchemaContext

func (*SchemaContext) ImplementMethods

func (s *SchemaContext) ImplementMethods(documents map[jsonschema.ID]Component)

ImplementMethods add's any methods that any struct might need to implement for any interfaces

func (*SchemaContext) Process

func (s *SchemaContext) Process(document Root, name string, schema *jsonschema.Schema) (Component, error)

Process a schema and return it as a tree of Types

func (*SchemaContext) RegisterMethodSignature

func (s *SchemaContext) RegisterMethodSignature(receiver string, methods ...*MethodSignature)

RegisterMethodSignature add's any methods onto the named receiver across all schemas so you can implement a interface from a reference etc

func (*SchemaContext) ResolveSchema

func (s *SchemaContext) ResolveSchema(ref jsonschema.Reference, arr ...*jsonschema.Schema) (*jsonschema.Schema, error)

ResolveSchema takes a Reference and uses it to walk the schema to find the matching subschema

func (*SchemaContext) ResolveTypename

func (s *SchemaContext) ResolveTypename(ref jsonschema.Reference, base *jsonschema.Schema) (string, error)

ResolveTypename takes a Reference and uses it to walk the schema to find the matching typename to reference

type Type

type Type struct {
	Kind Kind
	Name string
}

func NewType

func NewType(name string, kind Kind) *Type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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