codegen

package
v0.0.0-...-2c61642 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2021 License: Apache-2.0 Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsGoTypeWithInlineSupport

func AsGoTypeWithInlineSupport(e *DatatypeDef, parentGoName string, visitor *Visitor) string

func EventNameAsGoStructName

func EventNameAsGoStructName(e *EventSpec) string

func NewVersionData

func NewVersionData(version string) *versionData

func ProcessFile

func ProcessFile(target FileToGenerate, data interface{}) error

func ProcessModules

func ProcessModules(modules []*Module, opts Opts) error

func WriteTemplateFile

func WriteTemplateFile(filename string, data interface{}, templateString string) error

Types

type ApplicationTypesDefinition

type ApplicationTypesDefinition struct {
	StringConsts []StringConstDef     `json:"stringConsts"`
	Enums        []EnumDef            `json:"enums"`
	Types        []NamedDatatypeDef   `json:"types"`
	Endpoints    []EndpointDefinition `json:"endpoints"`
}

func (*ApplicationTypesDefinition) EndpointsProducesAndConsumesTypescriptTypes

func (a *ApplicationTypesDefinition) EndpointsProducesAndConsumesTypescriptTypes() []string

func (*ApplicationTypesDefinition) UniqueDatatypesFlattened

func (a *ApplicationTypesDefinition) UniqueDatatypesFlattened() []*DatatypeDef

func (*ApplicationTypesDefinition) Validate

func (a *ApplicationTypesDefinition) Validate() error

type CommandFieldSpec

type CommandFieldSpec struct {
	Key                string `json:"key"`
	Title              string `json:"title"`
	Type               string `json:"type"`
	Unit               string `json:"unit"`
	ValidationRegex    string `json:"validation_regex"`
	MaxLength          *int   `json:"max_length"`
	Optional           bool   `json:"optional"`
	HideIfDefaultValue bool   `json:"hideIfDefaultValue"`
	Help               string `json:"help"`
	Placeholder        string `json:"placeholder"`
}

func (*CommandFieldSpec) AsGoType

func (c *CommandFieldSpec) AsGoType(module *Module) string

func (*CommandFieldSpec) AsTsType

func (c *CommandFieldSpec) AsTsType() string

func (*CommandFieldSpec) AsValidationSnippet

func (c *CommandFieldSpec) AsValidationSnippet(module *Module) string

func (*CommandFieldSpec) Validate

func (c *CommandFieldSpec) Validate(module *Module) error

type CommandSpec

type CommandSpec struct {
	Command                string              `json:"command"`
	Title                  string              `json:"title"`
	CrudNature             string              `json:"crudNature"`
	AdditionalConfirmation string              `json:"additional_confirmation"`
	MiddlewareChain        string              `json:"chain"`
	CtorArgs               []string            `json:"ctor"`
	Fields                 []*CommandFieldSpec `json:"fields"`
	Info                   []string            `json:"info"`
}

func (*CommandSpec) AsGoStructName

func (c *CommandSpec) AsGoStructName() string

func (*CommandSpec) CtorArgsForTypeScript

func (c *CommandSpec) CtorArgsForTypeScript() string

func (*CommandSpec) CustomFields

func (c *CommandSpec) CustomFields() []CommandFieldSpec

func (*CommandSpec) FieldsForTypeScript

func (c *CommandSpec) FieldsForTypeScript(tplData *TplData) string

func (*CommandSpec) MakeValidation

func (c *CommandSpec) MakeValidation(module *Module) string

returns Go code (as a string) for validating command inputs

func (*CommandSpec) Validate

func (c *CommandSpec) Validate(module *Module) error

type CommandSpecFile

type CommandSpecFile []*CommandSpec

func (*CommandSpecFile) ImportedCustomFieldTypes

func (c *CommandSpecFile) ImportedCustomFieldTypes() []string

func (*CommandSpecFile) Validate

func (c *CommandSpecFile) Validate(module *Module) error

type DatatypeDef

type DatatypeDef struct {
	NameRaw  string                  `json:"_"` // "Type" | "module.Type" if referring to another module (such as "domain")
	Notes    string                  `json:"notes"`
	Nullable bool                    `json:"nullable"`
	Of       *DatatypeDef            `json:"of"`     // only used if Name==list
	Fields   map[string]*DatatypeDef `json:"fields"` // only used if Name==object
}

func (*DatatypeDef) AsGoType

func (e *DatatypeDef) AsGoType() string

func (*DatatypeDef) AsTypeScriptType

func (d *DatatypeDef) AsTypeScriptType() string

func (*DatatypeDef) FieldsSorted

func (d *DatatypeDef) FieldsSorted() []DatatypeDefField

func (*DatatypeDef) ModuleId

func (d *DatatypeDef) ModuleId() string

func (*DatatypeDef) Name

func (d *DatatypeDef) Name() string

type DatatypeDefField

type DatatypeDefField struct {
	Key  string
	Type *DatatypeDef
}

type DatatypeDefObjectField

type DatatypeDefObjectField struct {
	Key  string       `json:"key"`
	Type *DatatypeDef `json:"type"`
}

type DomainFile

type DomainFile struct {
	Events []*EventSpec `json:"events"`
}

type EndpointDefinition

type EndpointDefinition struct {
	Path            string       `json:"path"`
	HttpMethod      string       `json:"method"`
	Name            string       `json:"name"`
	MiddlewareChain string       `json:"chain"`
	Description     string       `json:"description"`
	Produces        *DatatypeDef `json:"produces"` // optional
	Consumes        *DatatypeDef `json:"consumes"` // optional
}

func (*EndpointDefinition) GoArgs

func (e *EndpointDefinition) GoArgs() string

"/users/{id}/addresses/{idx}" => "id string, idx string"

func (*EndpointDefinition) GoPath

func (e *EndpointDefinition) GoPath() string

FIXME: URL escaping "/users/{id}" => "/users/"+id+"" "/search?q={query}" => "/search?query="+query+""

func (*EndpointDefinition) TypescriptArgs

func (e *EndpointDefinition) TypescriptArgs() string

"/users/{id}/addresses/{idx}" => "id: string, idx: string"

func (*EndpointDefinition) TypescriptPath

func (e *EndpointDefinition) TypescriptPath() string

"/users/{id}" => "/users/${encodeURIComponent(id)}" "/search?q={query}" => "/search?query=${encodeURIComponent(query)}"

type EnumDef

type EnumDef struct {
	Name          string   `json:"name"`
	Type          string   `json:"type"`
	StringMembers []string `json:"stringMembers"`
}

type EventDefForTpl

type EventDefForTpl struct {
	EventKey        string
	CtorArgs        string
	CtorAssignments string
	GoStructName    string
}

func ProcessEvents

func ProcessEvents(file *DomainFile) ([]EventDefForTpl, string)

type EventFieldSpec

type EventFieldSpec struct {
	Key   string      `json:"key"`
	Type  DatatypeDef `json:"type"`
	Notes string      `json:"notes"`
}

type EventSpec

type EventSpec struct {
	Event     string            `json:"event"`
	CtorArgs  []string          `json:"ctor"`
	Changelog []string          `json:"changelog"`
	Fields    []*EventFieldSpec `json:"fields"`
}

type FileToGenerate

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

func CompanionFile

func CompanionFile(targetPath string) FileToGenerate

companion file means that for each of these files their corresponding .template file exists and will be rendered which will end up as the filename given

func Inline

func Inline(targetPath string, inline string) FileToGenerate

type GoStruct

type GoStruct struct {
	Name   string
	Fields []GoStructField
}

func VisitForGoStructs

func VisitForGoStructs(e *EventSpec, visitor *Visitor) *GoStruct

func (*GoStruct) AsGoCode

func (g *GoStruct) AsGoCode() string

func (*GoStruct) Field

func (g *GoStruct) Field(name string) *GoStructField

type GoStructField

type GoStructField struct {
	Name string
	Type string
	Tags string
}

func (*GoStructField) AsGoCode

func (g *GoStructField) AsGoCode() string

type Imports

type Imports struct {
	// native types
	Date     bool
	DateTime bool
	Binary   bool

	ModuleIds []string // other modules whose types this module's types have dependencies to
}

func NewImports

func NewImports() Imports

type Module

type Module struct {
	// config
	Id   string // "vstotypes"
	Path string // "vstoserver/vstotypes"

	// input files
	EventsSpecFile   string
	CommandsSpecFile string
	TypesFile        string
	UiRoutesFile     string

	// computed state
	Events   *DomainFile
	Types    *ApplicationTypesDefinition
	Commands *CommandSpecFile
	UiRoutes []uiRouteSpec
}

func NewModule

func NewModule(
	modulePath string,
	typesFile string,
	eventsSpecFile string,
	commandSpecFile string,
	uiRoutesFile string,
) *Module

func (*Module) HasEnum

func (m *Module) HasEnum(name string) bool

type NamedDatatypeDef

type NamedDatatypeDef struct {
	Name string       `json:"name"`
	Type *DatatypeDef `json:"type"`
}

func (*NamedDatatypeDef) AsToGoCode

func (s *NamedDatatypeDef) AsToGoCode() string

func (*NamedDatatypeDef) AsTypeScriptCode

func (s *NamedDatatypeDef) AsTypeScriptCode() string

type Opts

type Opts struct {
	BackendModulePrefix    string // "github.com/myorg/myproject/pkg/"
	FrontendModulePrefix   string // "generated/"
	AutogenerateModuleDocs bool
}

type ProcessedStringEnum

type ProcessedStringEnum struct {
	Name          string
	MembersDigest string
	Members       []ProcessedStringEnumMember
}

func ProcessStringEnums

func ProcessStringEnums(enums []EnumDef) []ProcessedStringEnum

type ProcessedStringEnumMember

type ProcessedStringEnumMember struct {
	Key     string
	GoKey   string
	GoValue string
}

type StringConstDef

type StringConstDef struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type TplData

type TplData struct {
	Module                 *Module
	Opts                   Opts
	AnyEndpointHasConsumes bool
	TypesImports           Imports
	CommandsImports        Imports
	CommandsImportsUi      Imports // UI only needs types that are mentioned in ctor
	EventsImports          Imports
	StringEnums            []ProcessedStringEnum
	EventStructsAsGoCode   string
	EventDefs              []EventDefForTpl
}

this is passed as data to each template that we'll render

type Visitor

type Visitor struct {
	Structs []GoStruct
}

func (*Visitor) AppendStruct

func (v *Visitor) AppendStruct(item GoStruct)

func (*Visitor) AsGoCode

func (v *Visitor) AsGoCode() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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