generator

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2019 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	XID           = "x-id"
	XGoVendorType = `x-go-vendor-type`
	XGoStarLevel  = `x-go-star-level`
	XGoFieldName  = `x-go-field-name`

	XTagValidate = `x-tag-validate`
	XTagMime     = `x-tag-mime`
	XTagJSON     = `x-tag-json`
	XTagXML      = `x-tag-xml`
	XTagName     = `x-tag-name`

	XEnumOptions = `x-enum-options`
	XStatusErrs  = `x-status-errors`
)

Variables

View Source
var RxHttpRouterPath = regexp.MustCompile("/:([^/]+)")

Functions

func BindSchemaValidationByValidateBytes

func BindSchemaValidationByValidateBytes(s *oas.Schema, typ types.Type, validateBytes []byte) error

func BindSchemaValidationByValidator

func BindSchemaValidationByValidator(s *oas.Schema, v validator.Validator)

Types

type DefinitionScanner

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

func NewDefinitionScanner

func NewDefinitionScanner(pkg *packagesx.Package) *DefinitionScanner

func (*DefinitionScanner) Bind

func (scanner *DefinitionScanner) Bind(openapi *oas.OpenAPI)

func (*DefinitionScanner) Def

func (scanner *DefinitionScanner) Def(typeName *types.TypeName) *oas.Schema

type OpenAPIGenerator

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

func NewOpenAPIGenerator

func NewOpenAPIGenerator(pkg *packagesx.Package) *OpenAPIGenerator

func (*OpenAPIGenerator) Output

func (g *OpenAPIGenerator) Output(cwd string)

func (*OpenAPIGenerator) Scan

func (g *OpenAPIGenerator) Scan()

type Operator

type Operator struct {
	ID string

	Tag         string
	Summary     string
	Description string

	NonBodyParameters map[string]*oas.Parameter
	RequestBody       *oas.RequestBody

	StatusErrors      []*statuserror.StatusErr
	StatusErrorSchema *oas.Schema

	SuccessStatus   int
	SuccessType     types.Type
	SuccessResponse *oas.Response
}

func (*Operator) AddNonBodyParameter

func (operator *Operator) AddNonBodyParameter(parameter *oas.Parameter)

func (*Operator) BindOperation

func (operator *Operator) BindOperation(method string, operation *oas.Operation, last bool)

func (*Operator) SetRequestBody

func (operator *Operator) SetRequestBody(requestBody *oas.RequestBody)

type OperatorScanner

type OperatorScanner struct {
	*DefinitionScanner
	*StatusErrScanner
	// contains filtered or unexported fields
}

func NewOperatorScanner

func NewOperatorScanner(pkg *packagesx.Package) *OperatorScanner

func (*OperatorScanner) Operator

func (scanner *OperatorScanner) Operator(typeName *types.TypeName) *Operator

type OperatorTypeName

type OperatorTypeName struct {
	Path string
	*types.TypeName
}

func (*OperatorTypeName) SingleStringResultOf

func (operator *OperatorTypeName) SingleStringResultOf(pkg *packagesx.Package, name string) (string, bool)

type Route

type Route struct {
	Method    string
	Path      string
	Operators operatorTypeNames
	// contains filtered or unexported fields
}

func (*Route) SetMethod

func (route *Route) SetMethod(pkg *packagesx.Package)

func (*Route) SetPath

func (route *Route) SetPath(pkg *packagesx.Package)

func (*Route) String

func (route *Route) String() string

type Router

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

func NewRouter

func NewRouter(operators ...*OperatorTypeName) *Router

func (*Router) AppendOperators

func (router *Router) AppendOperators(operators ...*OperatorTypeName)

func (*Router) Register

func (router *Router) Register(r *Router)

func (*Router) Route

func (router *Router) Route(pkg *packagesx.Package) *Route

func (*Router) Routes

func (router *Router) Routes(pkg *packagesx.Package) (routes []*Route)

func (*Router) With

func (router *Router) With(operators ...*OperatorTypeName)

type RouterScanner

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

func NewRouterScanner

func NewRouterScanner(pkg *packagesx.Package) *RouterScanner
Example
cwd, _ := os.Getwd()
pkg, _ := packagesx.Load(filepath.Join(cwd, "./__examples__/router_scanner"))

router := pkg.Var("Router")

scanner := NewRouterScanner(pkg)
routes := scanner.Router(router).Routes(pkg)

for _, r := range routes {
	fmt.Println(r.String())
}
Output:

GET /root/:id httptransport.GroupOperator auth.Auth main.Get
HEAD /root/group/health httptransport.GroupOperator httptransport.GroupOperator group.Health

func (*RouterScanner) Router

func (scanner *RouterScanner) Router(typeName *types.Var) *Router

type SchemaRefer

type SchemaRefer struct {
	*oas.Schema
}

func NewSchemaRefer

func NewSchemaRefer(s *oas.Schema) *SchemaRefer

func (SchemaRefer) RefString

func (r SchemaRefer) RefString() string

type StatusErrScanner

type StatusErrScanner struct {
	StatusErrType *types.Named
	// contains filtered or unexported fields
}

func NewStatusErrScanner

func NewStatusErrScanner(pkg *packagesx.Package) *StatusErrScanner

func (*StatusErrScanner) StatusErrorsInFunc

func (scanner *StatusErrScanner) StatusErrorsInFunc(typeFunc *types.Func) []*statuserror.StatusErr

type StructFieldUniqueChecker

type StructFieldUniqueChecker map[string]*types.Var

func (StructFieldUniqueChecker) Check

func (checker StructFieldUniqueChecker) Check(structType *types.Struct, anonymous bool) error

type VendorExtensible

type VendorExtensible interface {
	AddExtension(key string, value interface{})
}

Jump to

Keyboard shortcuts

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