gen

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorInlineStructForbidden = errors.New("inlined structs are forbidden to use, declare an explicit type")

Functions

func Capitalize

func Capitalize(s string) string

func GenerateClient

func GenerateClient(router *vel.Router, w io.Writer, config ClientGeneratorConfig) error

GenerateClient generates an API client and writes it to the provided writer

func GenerateClientToFile

func GenerateClientToFile(router *vel.Router, config ClientGeneratorConfig) error

GenerateClientToFile generates an API client and writes it to a file

func GenerateOpenAPI

func GenerateOpenAPI(router *vel.Router, w io.Writer, title, version string) error

func GenerateOpenAPIToFile

func GenerateOpenAPIToFile(router *vel.Router, outputPath, title, version string) error

GenerateOpenAPIToFile generates an OpenAPI specification and writes it to a file

func RegisterTemplate

func RegisterTemplate(name string, tpl *template.Template)

Types

type ApiClientDesc

type ApiClientDesc struct {
	Client ClientDesc
	Apis   []ApiDesc
}

type ApiDesc

type ApiDesc struct {
	Input       DataType
	Output      DataType
	OperationID string
	Method      string
	FuncName    string
	DataTypes   []DataType
	Spec        vel.Spec
}

type ClientDesc

type ClientDesc struct {
	TypeName      string
	PackageName   string
	TypeNameLower string
}

type ClientGen

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

ClientGen defines api client generator it doesn't support the following: - anonymous nested struct

func New

func New(clientDesc ClientDesc, meta []vel.HandlerMeta) (*ClientGen, error)

func (*ClientGen) Generate

func (g *ClientGen) Generate(w io.Writer, templateName, postProcessing string) error

func (*ClientGen) GenerateOpenAPI

func (g *ClientGen) GenerateOpenAPI(title, version string) (*OpenAPISpec, error)

GenerateOpenAPI generates an OpenAPI specification from the client metadata

func (*ClientGen) GenerateOpenAPIYAML

func (g *ClientGen) GenerateOpenAPIYAML(w io.Writer, title, version string) error

GenerateOpenAPIYAML generates OpenAPI YAML from the client metadata

type ClientGeneratorConfig

type ClientGeneratorConfig struct {
	TypeName    string
	PackageName string
	OutputDir   string
	Language    string // "go" or "ts"
	PostProcess string // e.g., "goimports" or "prettier"
}

ClientGeneratorConfig holds configuration for generating API clients

type DataType

type DataType struct {
	Name   string
	Fields []Field
	// OtherTypes defines a list of types required to generate the fields
	OtherTypes []DataType
}

type Field

type Field struct {
	Name       string
	Type       reflect.Type
	TypeName   string
	TSTypeName string // TypeScript type name
	JsonTag    string
	SchemaTag  string
	// IsBuiltin defines a flag that a field exists in std lib, therefore must not be broken down further
	// e.g. time.Time
	IsBuilting bool
}

type OpenAPIComponents

type OpenAPIComponents struct {
	Schemas map[string]*OpenAPISchema `yaml:"schemas"`
}

type OpenAPIContent

type OpenAPIContent struct {
	ApplicationJSON *OpenAPIMediaType `yaml:"application/json,omitempty"`
}

type OpenAPIHeader

type OpenAPIHeader struct {
	Description string         `yaml:"description,omitempty"`
	Required    bool           `yaml:"required,omitempty"`
	Schema      *OpenAPISchema `yaml:"schema"`
}

type OpenAPIInfo

type OpenAPIInfo struct {
	Title   string `yaml:"title"`
	Version string `yaml:"version"`
}

OpenAPI structures for generating OpenAPI specs

type OpenAPIMediaType

type OpenAPIMediaType struct {
	Schema *OpenAPISchema `yaml:"schema"`
}

type OpenAPIOperation

type OpenAPIOperation struct {
	OperationID string                      `yaml:"operationId"`
	Description string                      `yaml:"description,omitempty"`
	Parameters  []*OpenAPIParameter         `yaml:"parameters,omitempty"`
	RequestBody *OpenAPIRequestBody         `yaml:"requestBody,omitempty"`
	Responses   map[string]*OpenAPIResponse `yaml:"responses"`
}

type OpenAPIParameter

type OpenAPIParameter struct {
	Name        string         `yaml:"name"`
	In          string         `yaml:"in"`
	Description string         `yaml:"description,omitempty"`
	Required    bool           `yaml:"required"`
	Schema      *OpenAPISchema `yaml:"schema"`
	Example     interface{}    `yaml:"example,omitempty"`
}

type OpenAPIPathItem

type OpenAPIPathItem struct {
	Get  *OpenAPIOperation `yaml:"get,omitempty"`
	Post *OpenAPIOperation `yaml:"post,omitempty"`
}

type OpenAPIRequestBody

type OpenAPIRequestBody struct {
	Content *OpenAPIContent `yaml:"content"`
}

type OpenAPIResponse

type OpenAPIResponse struct {
	Description string                    `yaml:"description"`
	Content     *OpenAPIContent           `yaml:"content,omitempty"`
	Headers     map[string]*OpenAPIHeader `yaml:"headers,omitempty"`
}

type OpenAPISchema

type OpenAPISchema struct {
	Type                 string                    `yaml:"type,omitempty"`
	Properties           map[string]*OpenAPISchema `yaml:"properties,omitempty"`
	Items                *OpenAPISchema            `yaml:"items,omitempty"`
	AdditionalProperties *OpenAPISchema            `yaml:"additionalProperties,omitempty"`
	Required             []string                  `yaml:"required,omitempty"`
	Ref                  string                    `yaml:"$ref,omitempty"`
	Format               string                    `yaml:"format,omitempty"`
	MinLength            *int                      `yaml:"minLength,omitempty"`
	MaxLength            *int                      `yaml:"maxLength,omitempty"`
	Description          string                    `yaml:"description,omitempty"`
	Minimum              *int                      `yaml:"minimum,omitempty"`
	Maximum              *int                      `yaml:"maximum,omitempty"`
	Enum                 []string                  `yaml:"enum,omitempty"`
	Example              interface{}               `yaml:"example,omitempty"`
}

type OpenAPISpec

type OpenAPISpec struct {
	OpenAPI    string                      `yaml:"openapi"`
	Info       *OpenAPIInfo                `yaml:"info"`
	Paths      map[string]*OpenAPIPathItem `yaml:"paths"`
	Components *OpenAPIComponents          `yaml:"components"`
}

Jump to

Keyboard shortcuts

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