generator

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConvertToFloat32 = source.ConvertToFloat32
View Source
var ConvertToFloat64 = source.ConvertToFloat64
View Source
var HandlerName = generator.OperationName
View Source
var PrivateFieldName = generator.PrivateFieldName
View Source
var PublicFieldName = generator.PublicFieldName
View Source
var String = source.String

Functions

func NewClientBuilder

func NewClientBuilder(spec *openapi3.Swagger, handlers []Handler) (interface {
	Build() (*source.ClientFile, error)
}, error)

func NewPathParamsParsers

func NewPathParamsParsers(path string, params []PathParameter) ([]generator.Templater, error)

func PathName

func PathName(s string) string

Types

type ClientBuilder

type ClientBuilder struct {
	Hanlders []Handler
}

func (*ClientBuilder) Build

func (c *ClientBuilder) Build() (*source.ClientFile, error)

type Components

type Components struct {
	Schemas []GoTypeDef
}

func NewComponents

func NewComponents(spec openapi3.Components) Components

func (Components) String

func (c Components) String() (string, error)

type ConvertStrings

type ConvertStrings struct {
	ItemType SchemaRender
	From, To string
	MkErr    ErrorWrapper
}

func (ConvertStrings) ItemRender

func (c ConvertStrings) ItemRender(from, toOrig string) (string, error)

func (ConvertStrings) String

func (c ConvertStrings) String() (string, error)

type ErrorBuilder

type ErrorBuilder = source.ErrorBuilder

type ErrorWrapper

type ErrorWrapper = source.ErrorWrapper

type GoConstDef

type GoConstDef struct {
	Name  string
	Type  Render
	Value Render
}

func (GoConstDef) String

func (g GoConstDef) String() (string, error)

type GoFieldTag

type GoFieldTag struct {
	Key   string
	Value string
}

func (GoFieldTag) String

func (g GoFieldTag) String() (string, error)

type GoFile

type GoFile struct {
	DoNotEdit   bool
	PackageName string

	Imports []GoFileImport

	Renders []Render
}

func SpecFile

func SpecFile(packageName string, fileContent []byte) GoFile

func (GoFile) String

func (g GoFile) String() (string, error)

type GoFileImport

type GoFileImport struct {
	Alias   string
	Package string
}

type GoFunction

type GoFunction struct {
	Receiver GoFunctionArg
	Name     string
	Args     []GoFunctionArg
	Returns  []GoFunctionArg
	Body     Render
}

func MarshalJSONFunc

func MarshalJSONFunc(orig GoType, body GoStruct) GoFunction

func (GoFunction) String

func (g GoFunction) String() (string, error)

type GoFunctionArg

type GoFunctionArg struct {
	Var  string
	Type Render
}

func (GoFunctionArg) String

func (g GoFunctionArg) String() (string, error)

type GoMap

type GoMap struct {
	Key, Value SchemaRender
}

func (GoMap) Format

func (s GoMap) Format(_ string) source.Templater

func (GoMap) Optionable

func (GoMap) Optionable()

func (GoMap) Parser

func (s GoMap) Parser(from, to string, mkErr ErrorWrapper) Render

func (GoMap) String

func (s GoMap) String() (string, error)

type GoSlice

type GoSlice struct {
	Items SchemaRender
}

func (GoSlice) Format

func (s GoSlice) Format(v string) source.Templater

func (GoSlice) Optionable

func (GoSlice) Optionable()

func (GoSlice) Parser

func (s GoSlice) Parser(from, to string, mkErr ErrorWrapper) Render

func (GoSlice) String

func (s GoSlice) String() (string, error)

func (GoSlice) StringsParser

func (s GoSlice) StringsParser(from, to string, mkErr ErrorWrapper) Render

type GoStruct

type GoStruct struct {
	Fields []GoStructField
}

func (GoStruct) Format

func (g GoStruct) Format(s string) source.Templater

func (GoStruct) Parser

func (g GoStruct) Parser(from, to string, mkErr ErrorWrapper) Render

func (GoStruct) String

func (g GoStruct) String() (string, error)

type GoStructField

type GoStructField struct {
	Name    string
	Comment string
	Type    SchemaRender
	Tags    []GoFieldTag
}

func NewGoStructField

func NewGoStructField(name string, schema *openapi3.SchemaRef, description string) (zero GoStructField)

func NewGoStructFieldTags

func NewGoStructFieldTags(name string, schema *openapi3.SchemaRef, tags ...GoFieldTag) (zero GoStructField)

func NewGoStructFields

func NewGoStructFields(si SchemasItems) []GoStructField

func (GoStructField) GetTag

func (g GoStructField) GetTag(key string) (GoFieldTag, bool)

func (GoStructField) String

func (g GoStructField) String() (string, error)

type GoType

type GoType string
const (
	StringType GoType = "string"

	Int   GoType = "int"
	Int32 GoType = "int32"
	Int64 GoType = "int64"

	Float32 GoType = "float32"
	Float64 GoType = "float64"

	BooleanType GoType = "bool"
)

func (GoType) Format

func (g GoType) Format(s string) source.Templater

func (GoType) Parser

func (g GoType) Parser(from, to string, mkErr ErrorWrapper) Render

func (GoType) String

func (g GoType) String() (string, error)

type GoTypeDef

type GoTypeDef struct {
	Comment string
	Name    string
	Type    Render

	Methods []Render
}

func NewGoTypeDef

func NewGoTypeDef(i SchemasItem) GoTypeDef

func NewGoTypeDefs

func NewGoTypeDefs(si SchemasItems) []GoTypeDef

func (GoTypeDef) GoTypeRef

func (g GoTypeDef) GoTypeRef() GoType

func (GoTypeDef) String

func (g GoTypeDef) String() (string, error)

type GoValue

type GoValue string

func (GoValue) String

func (g GoValue) String() (string, error)

type GoVarDef

type GoVarDef struct {
	Name  string
	Type  Render
	Value Render
}

func (GoVarDef) String

func (g GoVarDef) String() (string, error)

type Handler

type Handler struct {
	generator.HandlerOld

	Path   string
	Method string

	Responses []Response

	Params struct {
		Query []Param
	}
}

func NewHandler

func NewHandler(p *openapi3.Operation, path specification.Path, method string, params openapi3.Parameters) (zero Handler, _ error)

type Handlers

type Handlers struct {
	Handlers []Handler

	IsWriteJSONFunc bool
}

func NewHandlers

func NewHandlers(s *specification.Spec, basePath string) (zero Handlers, _ error)

type HeaderItem

type HeaderItem struct {
	Name   string
	Header *openapi3.HeaderRef
}

func PathHeaders

func PathHeaders(spec openapi3.Headers) []HeaderItem

type HeaderParser

type HeaderParser struct {
	HeaderVarName string
	ParameterName string
	Convert       Render
	Required      bool
}

func (HeaderParser) String

func (i HeaderParser) String() (string, error)

type OptionalParam

type OptionalParam struct {
	SchemaRender
}

func (OptionalParam) Format

func (r OptionalParam) Format(s string) source.Templater

func (OptionalParam) String

func (r OptionalParam) String() (string, error)

type Param

type Param struct {
	Field  GoStructField
	Parser Render

	Parameter *openapi3.Parameter
}

func NewHeaderParam

func NewHeaderParam(p *openapi3.Parameter) Param

func NewQueryParam

func NewQueryParam(p *openapi3.Parameter) Param

type PathConstantParser

type PathConstantParser struct {
	Prefix   string
	FullPath string
}

func (PathConstantParser) String

func (p PathConstantParser) String() (string, error)

type PathItem

type PathItem struct {
	Path string
	Item *openapi3.PathItem
}

func Paths

func Paths(spec openapi3.Paths) []PathItem

type PathOperationItem

type PathOperationItem struct {
	Method    string
	Operation *openapi3.Operation
}

func PathOperations

func PathOperations(spec *openapi3.PathItem) []PathOperationItem

type PathParameter

type PathParameter struct {
	Name      string
	FieldName string
	// GoType    GoType
	Type SchemaRender

	Field GoStructField
}

func NewPathParameter

func NewPathParameter(p *openapi3.Parameter) PathParameter

type PathParameterParser

type PathParameterParser struct {
	Variable string

	Convert Render
	Error   ErrorBuilder
}

func (PathParameterParser) String

func (p PathParameterParser) String() (string, error)

type QueryParser

type QueryParser struct {
	QueryVarName  string
	ParameterName string
	Convert       Render
	Required      bool
}

func (QueryParser) String

func (i QueryParser) String() (string, error)

type ReRoute

type ReRoute struct {
	Prefix    string
	RouteName string
}

type Ref

type Ref string

func NewRef

func NewRef(ref string) Ref

func (Ref) Format

func (r Ref) Format(s string) source.Templater

func (Ref) Parser

func (r Ref) Parser(from, to string, mkErr ErrorWrapper) Render

func (Ref) String

func (r Ref) String() (string, error)

type Render

type Render = source.Render

func NewBodyRef

func NewBodyRef(spec *openapi3.RequestBodyRef) Render

func NewHeaderParser

func NewHeaderParser(p *openapi3.Parameter, field GoStructField) Render

func NewQueryParser

func NewQueryParser(p *openapi3.Parameter, field GoStructField) Render

func NewStringsParser

func NewStringsParser(s SchemaRender, from, toOrig string, isPointer bool, mkErr ErrorWrapper) Render

type Response

type Response struct {
	Name        string
	PrivateName string
	HandlerName string

	Description string
	Status      int
	IsDefault   bool

	ResponserInterfaceName string

	IsBody  bool
	Body    Render
	Headers []ResponseHeader

	Struct GoTypeDef

	Args []ResponseArg
}

func NewResponse

func NewResponse(s *openapi3.SchemaRef, handlerName string, responserName string, status, contentType string, resp *openapi3.Response, gap string, code string, response *openapi3.ResponseRef) Response

func (Response) String

func (r Response) String() (string, error)

type ResponseArg

type ResponseArg struct {
	FieldName string
	ArgName   string
	IsHeader  bool
	Type      Render
}

type ResponseHeader

type ResponseHeader struct {
	Name      string
	FieldName string
	Type      SchemaRender
}

type ResponseItem

type ResponseItem struct {
	Code     string
	Response *openapi3.ResponseRef
}

func PathResponses

func PathResponses(spec openapi3.Responses) []ResponseItem

type Route

type Route struct {
	Name string

	Handlers        []RouteHandler
	WildcardHandler *RouteHandler

	Routes            []ReRoute
	WildcardRouteName string
}

func NewRoutes

func NewRoutes(routePrefix string, handlers []Handler) ([]Route, error)

type RouteHandler

type RouteHandler struct {
	Prefix  string
	Methods []RouteMethod
}

type RouteMethod

type RouteMethod struct {
	Method      string
	HandlerName string
	Path        string
}

type Router

type Router struct {
	PackageName string
	BasePath    string

	SpecFile         string
	SpecFileExt      string
	BaseSpecFilename string

	Handlers []Handler

	Routes []Route
}

func NewRouter

func NewRouter(packageName string, handlers []Handler, spec *openapi3.Swagger, specRaw []byte, baseFilename, basePath string) (Router, error)

type SchemaRender

type SchemaRender interface {
	Render
	Parser(from, to string, _ ErrorWrapper) Render
	Format(s string) source.Templater
}

func NewOptionalParam

func NewOptionalParam(sr SchemaRender) SchemaRender

func NewSchema

func NewSchema(spec *openapi3.Schema) SchemaRender

func NewSchemaRef

func NewSchemaRef(spec *openapi3.SchemaRef) SchemaRender

type SchemasItem

type SchemasItem struct {
	Name   string
	Schema *openapi3.SchemaRef
}

type SchemasItems

type SchemasItems []SchemasItem

func NewSchemas

func NewSchemas(ss openapi3.Schemas) SchemasItems

type StringValue

type StringValue GoValue

func (StringValue) String

func (s StringValue) String() (string, error)

type StringsParser

type StringsParser interface {
	StringsParser(from, to string, _ ErrorWrapper) Render
}

type StructParser

type StructParser struct {
	From, To string
	Error    ErrorWrapper
}

func (StructParser) String

func (s StructParser) String() (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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