Documentation ¶
Index ¶
- Constants
- func DB(p cfg.Process, fn cfg.FileHandler, logger zerolog.Logger, schemas db.DB, ...) error
- func HasDBOutput(o cfg.Output) bool
- func HasOpenAPIOutput(o cfg.Output) bool
- func HasProtoOutput(o cfg.Output) bool
- func HasSQLOutput(o cfg.Output) bool
- func OpenAPI(p cfg.Process, fn cfg.FileHandler, l zerolog.Logger, groups openapi.FileGroups, ...) error
- func Proto(p cfg.Process, fn cfg.FileHandler, l zerolog.Logger, groups proto.PBFileGroups, ...) error
- func SQL(p cfg.Process, fn cfg.FileHandler, l zerolog.Logger, fileGroups sql.FileGroups, ...) error
- type Context
- func (c *Context) Aborted() error
- func (c *Context) ErrorIf(t bool, reason string) (string, error)
- func (c *Context) Funcs() plates.FuncMap
- func (c *Context) NotNeededIf(t bool, reason string) (string, error)
- func (c *Context) PackageName() string
- func (c *Context) ToCase(name string) string
- func (c *Context) WithParams(values ...any) (*Context, error)
- type EnumContext
- type EnumsContext
- type Error
- type FuncMapper
- type Imports
- type Initializer
- type MimeType
- type OpBody
- type OpResponse
- type OpenAPIFileContext
- func (o *OpenAPIFileContext) CheckAllTypes(pkg string, types ...string) string
- func (o *OpenAPIFileContext) ComponentParameters() openapi3.ParametersMap
- func (o *OpenAPIFileContext) ComponentSchemas() openapi3.Schemas
- func (o *OpenAPIFileContext) DefaultValues(val string) []string
- func (o *OpenAPIFileContext) EnumName(name string) string
- func (o *OpenAPIFileContext) EnumNew(name string) string
- func (o *OpenAPIFileContext) GetOpHappyResponse(pkg string, op *openapi3.Operation) OpResponse
- func (o *OpenAPIFileContext) GetOpHappyResponseKey(op *openapi3.Operation) string
- func (o *OpenAPIFileContext) GetOpHappyResponseMimeType(op *openapi3.Operation) string
- func (o *OpenAPIFileContext) GetOpHappyResponseType(pkg string, op *openapi3.Operation) string
- func (o *OpenAPIFileContext) GetRequestBody(op *openapi3.Operation) *OpBody
- func (o *OpenAPIFileContext) GetRequestBodySchemas(op *openapi3.Operation) []OpBody
- func (o *OpenAPIFileContext) GetType(currentPackage, name string, s *openapi3.SchemaRef) string
- func (o *OpenAPIFileContext) GetTypeName(pkg string, s *openapi3.SchemaRef) string
- func (o *OpenAPIFileContext) GoImports() []string
- func (o *OpenAPIFileContext) HasAnyAuth(op *openapi3.Operation) bool
- func (o *OpenAPIFileContext) HasAuthentication() bool
- func (o *OpenAPIFileContext) HasAuthorization() bool
- func (o *OpenAPIFileContext) HasBasicAuth() bool
- func (o *OpenAPIFileContext) HasBearerAuth() bool
- func (o *OpenAPIFileContext) HasComplexAuth() bool
- func (o *OpenAPIFileContext) HasExtension(s *openapi3.SchemaRef, ext string) bool
- func (o *OpenAPIFileContext) HasValidation(s *openapi3.SchemaRef) bool
- func (o *OpenAPIFileContext) Init() error
- func (o *OpenAPIFileContext) IsDefaultEnum(name string, s *openapi3.SchemaRef) bool
- func (o *OpenAPIFileContext) IsRequiredProperty(name string, s *openapi3.SchemaRef) bool
- func (o *OpenAPIFileContext) IsSimpleAuth(op *openapi3.Operation) bool
- func (o *OpenAPIFileContext) OpParams(path *openapi3.PathItem, op *openapi3.Operation) openapi3.Parameters
- func (o *OpenAPIFileContext) OpSecurity(op *openapi3.Operation) openapi3.SecurityRequirements
- func (o *OpenAPIFileContext) ParamIsEnum(param *openapi3.ParameterRef) bool
- func (o *OpenAPIFileContext) ParamIsEnumArray(param *openapi3.ParameterRef) bool
- func (o *OpenAPIFileContext) ParamIsOptionalType(param *openapi3.ParameterRef) bool
- func (o *OpenAPIFileContext) RefToName(ref string) string
- func (o *OpenAPIFileContext) RequiresAuthUser(op *openapi3.Operation) bool
- func (o *OpenAPIFileContext) SchemaEnums(schema *openapi3.SchemaRef) openapi3.Schemas
- func (o *OpenAPIFileContext) SchemaIsComplex(schema *openapi3.SchemaRef) bool
- func (o *OpenAPIFileContext) SchemaIsEnum(schema *openapi3.SchemaRef) bool
- func (o *OpenAPIFileContext) SchemaIsEnumArray(schema *openapi3.SchemaRef) bool
- func (o *OpenAPIFileContext) SchemaProperties(schema *openapi3.SchemaRef, includeRefs bool) openapi3.Schemas
- func (o *OpenAPIFileContext) SchemaPropertiesHaveDefaults(schema *openapi3.SchemaRef) bool
- func (o *OpenAPIFileContext) StripArray(name string) string
- func (o *OpenAPIFileContext) TypeOnly(name string) string
- func (o *OpenAPIFileContext) WithParams(values ...any) (*OpenAPIFileContext, error)
- type ProcessRunner
- type Properties
- type Property
- type ProtoContext
- type ProtoFileContext
- type ProtoFileGroupContext
- type Resource
- type ResourceMap
- type RuntimeParams
- type SQLContext
- type SQLFileContext
- type SQLFileGroupContext
- type SQLQueryContext
- type SchemaContext
- type SchemasContext
- func (s SchemasContext) GetType(c *db.Column, pkg string) string
- func (s *SchemasContext) Parameterize(cc db.Columns, format, pkg string) string
- func (s SchemasContext) PropertiesFromDB(cc db.Columns) Properties
- func (s SchemasContext) PropertyFromDB(c *db.Column) *Property
- func (s SchemasContext) Resources() ResourceMap
- type TableContext
- type TemplateInitializer
Constants ¶
const ( ErrInvalidDictParams = Error("invalid dict params in call to WithParams, must be key and value pairs") ErrInvalidDictKey = Error("invalid dict params in call to WithParams, must be key and value pairs") )
const ( DBAll = "DbAll" DBSchema = "DbSchema" DBTable = "DbTable" DBEnums = "DbEnums" DBEnum = "DbEnum" )
const ( ErrMissingRequirement = Error("requires") ErrNotNeeded = Error("not needed") ErrPermExists = Error("file exists") )
const ( ApplicationJSON = "application/json" ApplicationJSONL = "application/jsonl" ApplicationForm = "application/x-www-form-urlencoded" MultipartForm = "multipart/form-data" TextPlain = "text/plain" TextHTML = "text/html" TextCSV = "text/csv" )
const ( OpenAPIFile = "OpenAPIFile" OpenAPITag = "OpenAPITag" )
const ( ProtoAll = "ProtoAll" ProtoFileGroup = "ProtoFileGroup" ProtoFile = "ProtoFile" )
const ( SQLAll = "SQLAll" SQLFiles = "SQLFiles" SQLFile = "SQLFile" SQLQuery = "SQLQuery" )
const PermPrefix = "!"
const ValidTypeElems = 2
Variables ¶
This section is empty.
Functions ¶
func HasDBOutput ¶
func HasOpenAPIOutput ¶
func HasProtoOutput ¶
func HasSQLOutput ¶
func OpenAPI ¶
func OpenAPI(p cfg.Process, fn cfg.FileHandler, l zerolog.Logger, groups openapi.FileGroups, simulate bool) error
Types ¶
type Context ¶
type Context struct { // RuntimeParams are used for parameterized sub-templates RuntimeParams // Process provides the details of the currently executing Process cfg.Process // Logger provides logging features to the context helpers and templates Logger zerolog.Logger // AbortError allows cancelling saving of a file. See NotNeededIf. AbortError error }
func (*Context) Aborted ¶
Aborted is used to control file generation based on template execution. See NotNeededIf.
func (*Context) ErrorIf ¶
ErrorIf if given bool is true the execution is fatally aborted, and stops processing.
func (*Context) NotNeededIf ¶
NotNeededIf given bool is true the execution is aborted, and can be used to prevent generation of a file.
func (*Context) PackageName ¶
PackageName is a helper to extract the package name from a fully qualified package. It uses the Process.Params.Package as the source. Params.Package "github.com/domain/repo/package/subpackage" => "subpackage".
type EnumContext ¶
type EnumContext struct { db.Enum SchemasContext }
type EnumsContext ¶
type EnumsContext struct { db.Enums SchemasContext }
type FuncMapper ¶
type Imports ¶
type Imports stringlist.Strings
Imports tracks dynamic usage of objects. Because templates are executed in order, using this to populate a list at the top of a generated file requires precalculating all the imports. See SQLContext.Init as an example. Another option would be to create a buffer of generated code at the beginning, then generate the final output.
func (*Imports) Add ¶
Add filters duplicates and appends to the import list. Add works on uninitialized Imports objects.
func (*Imports) CheckPackage ¶
CheckPackage is used for type mapping. Currently, it is designed for go fully qualified package names. Examples: "github.com/domain/repo/package/subpackage.Type", "" => "subpackage.Type" "time.Time", "" => "time.Time" "int", "" => "int" "github.com/domain/repo/package/subpackage.Type", "github.com/domain/repo/package/subpackage" => "Type" If the type is defined in a separate package the package is added to the import list.
type Initializer ¶
type Initializer interface {
Init() error
}
type MimeType ¶ added in v0.1.3
type MimeType string
func (MimeType) IsLongPollingOperation ¶ added in v0.1.3
func (MimeType) IsMultipartForm ¶ added in v0.3.4
type OpResponse ¶
type OpenAPIFileContext ¶
func (*OpenAPIFileContext) CheckAllTypes ¶
func (o *OpenAPIFileContext) CheckAllTypes(pkg string, types ...string) string
CheckAllTypes is a helper to iterate all property references for import requirements. This is expected to inject imports for unnecessary packages depending on the template generated, the post-processing should remove unused imports.
func (*OpenAPIFileContext) ComponentParameters ¶ added in v0.1.0
func (o *OpenAPIFileContext) ComponentParameters() openapi3.ParametersMap
func (*OpenAPIFileContext) ComponentSchemas ¶ added in v0.1.0
func (o *OpenAPIFileContext) ComponentSchemas() openapi3.Schemas
func (*OpenAPIFileContext) DefaultValues ¶ added in v0.1.0
func (o *OpenAPIFileContext) DefaultValues(val string) []string
func (*OpenAPIFileContext) EnumName ¶ added in v0.1.0
func (o *OpenAPIFileContext) EnumName(name string) string
func (*OpenAPIFileContext) EnumNew ¶ added in v0.1.0
func (o *OpenAPIFileContext) EnumNew(name string) string
func (*OpenAPIFileContext) GetOpHappyResponse ¶
func (o *OpenAPIFileContext) GetOpHappyResponse(pkg string, op *openapi3.Operation) OpResponse
func (*OpenAPIFileContext) GetOpHappyResponseKey ¶
func (o *OpenAPIFileContext) GetOpHappyResponseKey(op *openapi3.Operation) string
func (*OpenAPIFileContext) GetOpHappyResponseMimeType ¶
func (o *OpenAPIFileContext) GetOpHappyResponseMimeType(op *openapi3.Operation) string
func (*OpenAPIFileContext) GetOpHappyResponseType ¶
func (o *OpenAPIFileContext) GetOpHappyResponseType(pkg string, op *openapi3.Operation) string
func (*OpenAPIFileContext) GetRequestBody ¶ added in v0.0.7
func (o *OpenAPIFileContext) GetRequestBody(op *openapi3.Operation) *OpBody
func (*OpenAPIFileContext) GetRequestBodySchemas ¶ added in v0.3.4
func (o *OpenAPIFileContext) GetRequestBodySchemas(op *openapi3.Operation) []OpBody
func (*OpenAPIFileContext) GetType ¶
func (o *OpenAPIFileContext) GetType(currentPackage, name string, s *openapi3.SchemaRef) string
func (*OpenAPIFileContext) GetTypeName ¶
func (o *OpenAPIFileContext) GetTypeName(pkg string, s *openapi3.SchemaRef) string
func (*OpenAPIFileContext) GoImports ¶ added in v0.0.7
func (o *OpenAPIFileContext) GoImports() []string
func (*OpenAPIFileContext) HasAnyAuth ¶
func (o *OpenAPIFileContext) HasAnyAuth(op *openapi3.Operation) bool
func (*OpenAPIFileContext) HasAuthentication ¶ added in v0.0.7
func (o *OpenAPIFileContext) HasAuthentication() bool
func (*OpenAPIFileContext) HasAuthorization ¶
func (o *OpenAPIFileContext) HasAuthorization() bool
func (*OpenAPIFileContext) HasBasicAuth ¶
func (o *OpenAPIFileContext) HasBasicAuth() bool
func (*OpenAPIFileContext) HasBearerAuth ¶
func (o *OpenAPIFileContext) HasBearerAuth() bool
func (*OpenAPIFileContext) HasComplexAuth ¶
func (o *OpenAPIFileContext) HasComplexAuth() bool
func (*OpenAPIFileContext) HasExtension ¶ added in v0.1.0
func (o *OpenAPIFileContext) HasExtension(s *openapi3.SchemaRef, ext string) bool
func (*OpenAPIFileContext) HasValidation ¶
func (o *OpenAPIFileContext) HasValidation(s *openapi3.SchemaRef) bool
func (*OpenAPIFileContext) Init ¶
func (o *OpenAPIFileContext) Init() error
func (*OpenAPIFileContext) IsDefaultEnum ¶
func (o *OpenAPIFileContext) IsDefaultEnum(name string, s *openapi3.SchemaRef) bool
IsDefaultEnum helper that checks if an enumerated type is overridden (specified externally).
func (*OpenAPIFileContext) IsRequiredProperty ¶ added in v0.1.14
func (o *OpenAPIFileContext) IsRequiredProperty(name string, s *openapi3.SchemaRef) bool
IsRequiredProperty helper that checks if a property is required.
func (*OpenAPIFileContext) IsSimpleAuth ¶
func (o *OpenAPIFileContext) IsSimpleAuth(op *openapi3.Operation) bool
func (*OpenAPIFileContext) OpParams ¶ added in v0.1.0
func (o *OpenAPIFileContext) OpParams(path *openapi3.PathItem, op *openapi3.Operation) openapi3.Parameters
func (*OpenAPIFileContext) OpSecurity ¶
func (o *OpenAPIFileContext) OpSecurity(op *openapi3.Operation) openapi3.SecurityRequirements
func (*OpenAPIFileContext) ParamIsEnum ¶ added in v0.1.0
func (o *OpenAPIFileContext) ParamIsEnum(param *openapi3.ParameterRef) bool
func (*OpenAPIFileContext) ParamIsEnumArray ¶ added in v0.1.0
func (o *OpenAPIFileContext) ParamIsEnumArray(param *openapi3.ParameterRef) bool
func (*OpenAPIFileContext) ParamIsOptionalType ¶ added in v0.1.0
func (o *OpenAPIFileContext) ParamIsOptionalType(param *openapi3.ParameterRef) bool
func (*OpenAPIFileContext) RefToName ¶
func (o *OpenAPIFileContext) RefToName(ref string) string
func (*OpenAPIFileContext) RequiresAuthUser ¶
func (o *OpenAPIFileContext) RequiresAuthUser(op *openapi3.Operation) bool
func (*OpenAPIFileContext) SchemaEnums ¶ added in v0.1.0
func (o *OpenAPIFileContext) SchemaEnums(schema *openapi3.SchemaRef) openapi3.Schemas
func (*OpenAPIFileContext) SchemaIsComplex ¶ added in v0.1.0
func (o *OpenAPIFileContext) SchemaIsComplex(schema *openapi3.SchemaRef) bool
func (*OpenAPIFileContext) SchemaIsEnum ¶ added in v0.3.4
func (o *OpenAPIFileContext) SchemaIsEnum(schema *openapi3.SchemaRef) bool
func (*OpenAPIFileContext) SchemaIsEnumArray ¶ added in v0.3.4
func (o *OpenAPIFileContext) SchemaIsEnumArray(schema *openapi3.SchemaRef) bool
func (*OpenAPIFileContext) SchemaProperties ¶ added in v0.1.0
func (*OpenAPIFileContext) SchemaPropertiesHaveDefaults ¶ added in v0.3.4
func (o *OpenAPIFileContext) SchemaPropertiesHaveDefaults(schema *openapi3.SchemaRef) bool
func (*OpenAPIFileContext) StripArray ¶ added in v0.1.0
func (o *OpenAPIFileContext) StripArray(name string) string
func (*OpenAPIFileContext) TypeOnly ¶ added in v0.0.7
func (o *OpenAPIFileContext) TypeOnly(name string) string
func (*OpenAPIFileContext) WithParams ¶
func (o *OpenAPIFileContext) WithParams(values ...any) (*OpenAPIFileContext, error)
type ProcessRunner ¶
func NewProcessRunner ¶
func NewProcessRunner(dir string, fn cfg.FileHandler, l zerolog.Logger, simulate bool) ProcessRunner
type Properties ¶
type Properties []*Property
type ProtoContext ¶
type ProtoContext struct { Context Imports FileGroups proto.PBFileGroups }
func (ProtoContext) HasMessage ¶
func (q ProtoContext) HasMessage(msg *proto.Message) bool
func (ProtoContext) IsEnum ¶
func (q ProtoContext) IsEnum(name string) bool
func (ProtoContext) IsMessage ¶
func (q ProtoContext) IsMessage(name string) bool
type ProtoFileContext ¶
type ProtoFileContext struct { ProtoFileGroupContext proto.PBFile }
type ProtoFileGroupContext ¶
type ProtoFileGroupContext struct { ProtoContext FileGroup proto.PBFileGroup }
type Resource ¶
type Resource struct { Name string Properties Properties Table *db.Table PK *Property }
type ResourceMap ¶
type RuntimeParams ¶
type SQLContext ¶
type SQLContext struct { Context sql.FileGroups Imports }
func (*SQLContext) Init ¶
func (q *SQLContext) Init() error
func (SQLContext) Parameterize ¶
func (q SQLContext) Parameterize(cc sql.Params, format, pkg string) string
type SQLFileContext ¶
type SQLFileContext struct { SQLContext sql.File }
type SQLFileGroupContext ¶
type SQLFileGroupContext struct { SQLContext Files []sql.File }
func (*SQLFileGroupContext) Init ¶
func (q *SQLFileGroupContext) Init() error
type SQLQueryContext ¶
type SQLQueryContext struct { SQLContext sql.Query }
func (*SQLQueryContext) Init ¶
func (q *SQLQueryContext) Init() error
type SchemaContext ¶
type SchemaContext struct { db.Schema SchemasContext }
type SchemasContext ¶
func (*SchemasContext) Parameterize ¶
func (s *SchemasContext) Parameterize(cc db.Columns, format, pkg string) string
func (SchemasContext) PropertiesFromDB ¶
func (s SchemasContext) PropertiesFromDB(cc db.Columns) Properties
func (SchemasContext) PropertyFromDB ¶
func (s SchemasContext) PropertyFromDB(c *db.Column) *Property
func (SchemasContext) Resources ¶
func (s SchemasContext) Resources() ResourceMap
type TableContext ¶
type TableContext struct { db.Table SchemasContext }