generator

package
v1.21.3 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2021 License: MIT Imports: 35 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`

	XEnumLabels = `x-enum-labels`
	// Deprecated  use XEnumLabels
	XEnumOptions = `x-enum-options`
	XStatusErrs  = `x-status-errors`
)

Variables

This section is empty.

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) BindSchemas

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

func (*DefinitionScanner) Def

func (scanner *DefinitionScanner) Def(ctx context.Context, typeName *types.TypeName) *oas.Schema

func (*DefinitionScanner) GetSchemaByType

func (scanner *DefinitionScanner) GetSchemaByType(ctx context.Context, typ types.Type) *oas.Schema

type OpenAPIGenerator

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

func NewOpenAPIGenerator

func NewOpenAPIGenerator(pkg *packagesx.Package) *OpenAPIGenerator

func (*OpenAPIGenerator) OperationByOperatorTypes

func (g *OpenAPIGenerator) OperationByOperatorTypes(method string, operatorTypes ...*OperatorWithTypeName) *oas.Operation

func (*OpenAPIGenerator) Output

func (g *OpenAPIGenerator) Output(cwd string)

func (*OpenAPIGenerator) Scan

func (g *OpenAPIGenerator) Scan(ctx context.Context)

type Operator

type Operator struct {
	httptransport.RouteMeta

	Tag         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(ctx context.Context, typeName *types.TypeName) *Operator

type OperatorWithTypeName

type OperatorWithTypeName struct {
	*Operator
	TypeName *types.TypeName
}

func (*OperatorWithTypeName) String

func (operator *OperatorWithTypeName) String() string

type Route

type Route struct {
	Operators []*OperatorWithTypeName
	// contains filtered or unexported fields
}

func (*Route) Method

func (route *Route) Method() string

func (*Route) Path

func (route *Route) Path() string

func (*Route) String

func (route *Route) String() string

type Router

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

func NewRouter

func NewRouter(typeVar *types.Var, operators ...*OperatorWithTypeName) *Router

func (*Router) AppendOperators

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

func (*Router) Name

func (r *Router) Name() string

func (*Router) Register

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

func (*Router) Route

func (router *Router) Route() *Route

func (*Router) Routes

func (router *Router) Routes() (routes []*Route)

func (*Router) String

func (r *Router) String() string

func (*Router) With

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

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()

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

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

func (*RouterScanner) OperatorTypeNameFromType

func (scanner *RouterScanner) OperatorTypeNameFromType(typ types.Type) *OperatorWithTypeName

func (*RouterScanner) OperatorTypeNamesFromArgs

func (scanner *RouterScanner) OperatorTypeNamesFromArgs(pkg *packagesx.Package, args ...ast.Expr) []*OperatorWithTypeName

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 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