Documentation
¶
Index ¶
- func GenerateSchema(schema *jsonschema.Schema, fs FileSystem, opts GenerateSchemaOptions) error
- func TypeFormatMapping() map[jsonschema.SchemaType]map[string]ir.PrimitiveType
- type DefaultElem
- type Elem
- type ErrBuildRouter
- type ErrNotImplemented
- type ErrParseSpec
- type ErrUnsupportedContentTypes
- type FileSystem
- type Filters
- type GenerateSchemaOptions
- type Generator
- type MethodRoute
- type Options
- type ResponseElem
- type Route
- type RouteNode
- func (n *RouteNode) Children() []*RouteNode
- func (n *RouteNode) Head() byte
- func (n *RouteNode) IsLeaf() bool
- func (n *RouteNode) IsParam() bool
- func (n *RouteNode) IsStatic() bool
- func (n *RouteNode) Operation() *ir.Operation
- func (n *RouteNode) Param() *ir.Parameter
- func (n *RouteNode) ParamChildren() (r []*RouteNode)
- func (n *RouteNode) ParamName() string
- func (n *RouteNode) Prefix() string
- func (n *RouteNode) StaticChildren() (r []*RouteNode)
- func (n *RouteNode) Tails() (r []byte)
- type RouteTree
- type Router
- type RouterElem
- type TemplateConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateSchema ¶ added in v0.21.0
func GenerateSchema(schema *jsonschema.Schema, fs FileSystem, opts GenerateSchemaOptions) error
GenerateSchema generates type, validation and JSON encoding for given schema.
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.
type ErrBuildRouter ¶ added in v0.16.0
type ErrBuildRouter struct {
// contains filtered or unexported fields
}
ErrBuildRouter reports that route tree building failed.
func (*ErrBuildRouter) Error ¶ added in v0.16.0
func (e *ErrBuildRouter) Error() string
Error implements error.
func (*ErrBuildRouter) Unwrap ¶ added in v0.16.0
func (e *ErrBuildRouter) Unwrap() error
Unwrap implements errors.Wrapper.
type ErrNotImplemented ¶
type ErrNotImplemented struct {
Name string
}
ErrNotImplemented reports that feature is not implemented.
func (*ErrNotImplemented) Error ¶
func (e *ErrNotImplemented) Error() string
Error implements error.
type ErrParseSpec ¶ added in v0.16.0
type ErrParseSpec struct {
// contains filtered or unexported fields
}
ErrParseSpec reports that specification parsing failed.
func (*ErrParseSpec) Error ¶ added in v0.16.0
func (e *ErrParseSpec) Error() string
Error implements error.
func (*ErrParseSpec) Unwrap ¶ added in v0.16.0
func (e *ErrParseSpec) Unwrap() error
Unwrap implements errors.Wrapper.
type ErrUnsupportedContentTypes ¶
type ErrUnsupportedContentTypes struct {
ContentTypes []string
}
ErrUnsupportedContentTypes reports that ogen does not support such content-type(s).
func (*ErrUnsupportedContentTypes) Error ¶
func (e *ErrUnsupportedContentTypes) Error() string
Error implements error.
type FileSystem ¶
FileSystem represents a directory of generated package.
type GenerateSchemaOptions ¶ added in v0.29.0
type GenerateSchemaOptions struct {
// TypeName is root schema type name. Defaults to "Type".
TypeName string
// FileName is output filename. Defaults to "output.gen.go".
FileName string
// PkgName is the package name. Defaults to GOPACKAGE environment variable, if any. Otherwise, to "output".
PkgName string
// TrimPrefix is a ref name prefixes to trim. Defaults to []string{"#/definitions/", "#/$defs/"}.
TrimPrefix []string
}
GenerateSchemaOptions is options structure for GenerateSchema.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator is OpenAPI-to-Go generator.
func NewGenerator ¶
NewGenerator creates new Generator.
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
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 whether to print routes.
VerboseRoute bool
// GenerateExampleTests whether to generate decoding tests using schema examples.
GenerateExampleTests bool
// SkipTestRegex is regex to skip generated tests.
SkipTestRegex *regexp.Regexp
// SkipUnimplemented disables generation of unimplemented Handler, like UnimplementedServer generated by gRPC.
SkipUnimplemented bool
// InferSchemaType enables type inference for schemas. Schema parser will try to detect schema type
// by its properties.
InferSchemaType bool
// Filters contains filters to skip operations.
Filters Filters
// IgnoreNotImplemented contains ErrNotImplemented messages to ignore.
IgnoreNotImplemented []string
// NotImplementedHook is hook for ErrNotImplemented errors.
NotImplementedHook func(name string, err error)
}
Options is Generator options.
type ResponseElem ¶
type ResponseElem struct {
Response *ir.StatusResponse
Ptr bool
}
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) ParamChildren ¶ added in v0.7.0
ParamChildren returns slice of child parameter nodes.
func (*RouteNode) StaticChildren ¶ added in v0.7.0
StaticChildren returns slice of child static nodes.
type RouteTree ¶ added in v0.7.0
type RouteTree struct {
Root *RouteNode
}
RouteTree is Radix tree of routes.
type Router ¶
type Router struct {
Methods []MethodRoute
// MaxParametersCount is maximum number of path parameters in one operation.
MaxParametersCount int
}
Router contains list of routes.
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
Securities map[string]*ir.Security
Router Router
// contains filtered or unexported fields
}
func (TemplateConfig) RatStrings ¶ added in v0.16.0
func (t TemplateConfig) RatStrings() []string
RatStrings returns slice of all unique big.Rat (multipleOf validation).
func (TemplateConfig) RegexStrings ¶ added in v0.5.0
func (t TemplateConfig) RegexStrings() []string
RegexStrings returns slice of all unique regex validators.
Source Files
¶
- errors.go
- fix.go
- gen_contents.go
- gen_operation.go
- gen_parameters.go
- gen_request_body.go
- gen_responses.go
- gen_schema.go
- gen_security.go
- genctx.go
- generator.go
- generics.go
- names.go
- panic.go
- reduce.go
- route_node.go
- route_tree.go
- router.go
- schema_gen.go
- schema_gen_primitive.go
- schema_gen_sum.go
- templates.go
- tstorage.go
- utils.go
- walk.go
- write.go