gen

package
v0.17.2-alpha.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2022 License: Apache-2.0 Imports: 22 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TypeFormatMapping added in v0.15.0

func TypeFormatMapping() map[jsonschema.SchemaType]map[string]ir.PrimitiveType

Types

type DefaultElem added in v0.15.0

type DefaultElem struct {
	// Type is type of this DefaultElem.
	Type *ir.Type
	// Var is decoding/encoding variable Go name (obj) or selector (obj.Field).
	Var string
	// Default is default value to set.
	Default ir.Default
}

DefaultElem is variable helper for setting default values.

type Elem

type Elem struct {
	// Sub whether this Elem has parent Elem.
	Sub bool
	// Type is type of this Elem.
	Type *ir.Type
	// Var is decoding/encoding variable Go name (obj) or selector (obj.Field).
	Var string
	// Tag contains info about field tags, if any.
	Tag ir.Tag
	// First whether this field is first.
	First bool
}

Elem is variable helper for recursive array or object encoding or decoding.

func (Elem) NextVar

func (e Elem) NextVar() string

NextVar returns name of variable for decoding recursive call.

Needed to make variable names unique.

type ErrBuildRouter added in v0.16.0

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

func (*ErrBuildRouter) Error added in v0.16.0

func (e *ErrBuildRouter) Error() string

func (*ErrBuildRouter) Unwrap added in v0.16.0

func (e *ErrBuildRouter) Unwrap() error

type ErrNotImplemented

type ErrNotImplemented struct {
	Name string
}

func (*ErrNotImplemented) Error

func (e *ErrNotImplemented) Error() string

type ErrParseSpec added in v0.16.0

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

func (*ErrParseSpec) Error added in v0.16.0

func (e *ErrParseSpec) Error() string

func (*ErrParseSpec) Unwrap added in v0.16.0

func (e *ErrParseSpec) Unwrap() error

type ErrUnsupportedContentTypes

type ErrUnsupportedContentTypes struct {
	ContentTypes []string
}

func (*ErrUnsupportedContentTypes) Error

type FileSystem

type FileSystem interface {
	WriteFile(baseName string, source []byte) error
}

FileSystem represents a directory of generated package.

type Filters added in v0.15.0

type Filters struct {
	PathRegex *regexp.Regexp
	Methods   []string
}

type Generator

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

func NewGenerator

func NewGenerator(spec *ogen.Spec, opts Options) (*Generator, error)

func (*Generator) WriteSource

func (g *Generator) WriteSource(fs FileSystem, pkgName string) error

WriteSource writes generated definitions to fs.

type MethodRoute added in v0.7.0

type MethodRoute struct {
	Method string
	Tree   RouteTree
}

MethodRoute is route for one Method.

func (*MethodRoute) Add added in v0.7.0

func (m *MethodRoute) Add(r Route) error

Add adds route to this tree.

type Options

type Options struct {
	VerboseRoute         bool
	GenerateExampleTests bool
	SkipTestRegex        *regexp.Regexp
	InferSchemaType      bool
	Filters              Filters
	IgnoreNotImplemented []string
	NotImplementedHook   func(name string, err error)
}

type ResponseElem

type ResponseElem struct {
	Response *ir.StatusResponse
	Ptr      bool
}

type Route

type Route struct {
	Method    string        // GET, POST, DELETE
	Operation *ir.Operation // getUserInfo
	Path      string        // /api/v1/user/{name}/info
}

type RouteNode added in v0.7.0

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

RouteNode is node of Radix tree of routes.

func (*RouteNode) Children added in v0.7.0

func (n *RouteNode) Children() []*RouteNode

Children returns child nodes.

func (*RouteNode) Head added in v0.7.0

func (n *RouteNode) Head() byte

Head returns first byte of prefix.

func (*RouteNode) IsLeaf added in v0.7.0

func (n *RouteNode) IsLeaf() bool

IsLeaf whether node has no children.

func (*RouteNode) IsParam added in v0.7.0

func (n *RouteNode) IsParam() bool

IsParam whether node is a parameter node.

func (*RouteNode) IsStatic added in v0.7.0

func (n *RouteNode) IsStatic() bool

IsStatic whether node is not a parameter node.

func (*RouteNode) Operation added in v0.7.0

func (n *RouteNode) Operation() *ir.Operation

Operation returns associated operation.

func (*RouteNode) Param added in v0.7.0

func (n *RouteNode) Param() *ir.Parameter

Param returns associated parameter, if any.

May be nil.

func (*RouteNode) ParamChildren added in v0.7.0

func (n *RouteNode) ParamChildren() (r []*RouteNode)

ParamChildren returns slice of child parameter nodes.

func (*RouteNode) ParamName added in v0.7.0

func (n *RouteNode) ParamName() string

ParamName returns parameter name, if any.

func (*RouteNode) Prefix added in v0.7.0

func (n *RouteNode) Prefix() string

Prefix returns common prefix.

func (*RouteNode) StaticChildren added in v0.7.0

func (n *RouteNode) StaticChildren() (r []*RouteNode)

StaticChildren returns slice of child static nodes.

func (*RouteNode) Tails added in v0.7.0

func (n *RouteNode) Tails() (r []byte)

Tails returns heads of child nodes.

Used for matching end of parameter node between two static.

type RouteTree added in v0.7.0

type RouteTree struct {
	Root *RouteNode
}

RouteTree is Radix tree of routes.

func (*RouteTree) Walk added in v0.7.0

func (t *RouteTree) Walk(cb func(level int, n *RouteNode))

type Router

type Router struct {
	Methods []MethodRoute
	// MaxParametersCount is maximum number of path parameters in one operation.
	MaxParametersCount int
}

Router contains list of routes.

func (*Router) Add added in v0.7.0

func (s *Router) Add(r Route) error

Add adds new route.

type RouterElem added in v0.8.0

type RouterElem struct {
	// ParameterIndex is index of parameter of this route part.
	ParameterIndex int
	Route          *RouteNode
}

RouterElem is variable helper for router generation.

type TemplateConfig

type TemplateConfig struct {
	Package    string
	Operations []*ir.Operation
	Types      map[string]*ir.Type
	Interfaces map[string]*ir.Type
	Error      *ir.StatusResponse
	ErrorType  *ir.Type
	Router     Router
	// contains filtered or unexported fields
}

func (TemplateConfig) RatStrings added in v0.16.0

func (t TemplateConfig) RatStrings() (r []string)

RatStrings returns slice of all unique big.Rat (multipleOf validation).

func (TemplateConfig) RegexStrings added in v0.5.0

func (t TemplateConfig) RegexStrings() (r []string)

RegexStrings returns slice of all unique regex validators.

func (TemplateConfig) SkipTest added in v0.10.1

func (t TemplateConfig) SkipTest(typ *ir.Type) bool

SkipTest returns true, if test should be skipped.

Jump to

Keyboard shortcuts

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