codegen

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2025 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action added in v0.3.0

type Action string
const (
	ActionList     Action = "list"
	ActionRetrieve Action = "retrieve"
	ActionCreate   Action = "create"
	ActionUpdate   Action = "update"
	ActionDelete   Action = "delete"
)

type Codegen added in v0.2.0

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

func New added in v0.2.0

func New(
	models fs.FS,
	templates fs.FS,
	outputPath string,
) (*Codegen, error)

func (*Codegen) Generate added in v0.2.0

func (g *Codegen) Generate(models ...string) ([]string, error)

type Entity

type Entity struct {
	Name        string   `hcl:"name,label"`
	Description *string  `hcl:"description,optional"`
	Fields      []*Field `hcl:"field,block"`
}

func (*Entity) PluralName

func (e *Entity) PluralName() string

type EntityReference

type EntityReference struct {
	Entity      string  `hcl:"entity"`
	Description *string `hcl:"description,optional"`
	Array       *bool   `hcl:"array,optional"`
}

type Enum

type Enum struct {
	Name        string       `hcl:"name,label"`
	Description *string      `hcl:"description"`
	Type        string       `hcl:"type"`
	RawExample  *cty.Value   `hcl:"example,optional"`
	RawValues   []*cty.Value `hcl:"values"`
}

func (*Enum) Example

func (e *Enum) Example() (any, error)

func (*Enum) Values

func (e *Enum) Values() ([]any, error)

type Field

type Field struct {
	Name        string     `hcl:"name,label"`
	Description *string    `hcl:"description,optional"`
	Type        string     `hcl:"type"`
	Sensitive   *bool      `hcl:"sensitive,optional"`
	Array       *bool      `hcl:"array,optional"`
	RawExample  *cty.Value `hcl:"example,optional"`
}

func (*Field) Example

func (f *Field) Example() (any, error)

type Method

type Method string
const (
	MethodConnect Method = http.MethodConnect
	MethodDelete  Method = http.MethodDelete
	MethodGet     Method = http.MethodGet
	MethodHead    Method = http.MethodHead
	MethodOptions Method = http.MethodOptions
	MethodPatch   Method = http.MethodPatch
	MethodPost    Method = http.MethodPost
	MethodPut     Method = http.MethodPut
	MethodTrace   Method = http.MethodTrace
)

type Model

type Model struct {
	Package    string       `hcl:"package"`
	Name       string       `hcl:"name"`
	Entities   []*Entity    `hcl:"entity,block"`
	Enums      []*Enum      `hcl:"enum,block"`
	Operations []*Operation `hcl:"operation,block"`
}

func (*Model) Entity

func (m *Model) Entity(name string) (*Entity, error)

func (*Model) Enum

func (m *Model) Enum(name string) (*Enum, error)

func (*Model) IsEntity

func (m *Model) IsEntity(name string) bool

func (*Model) IsEnum

func (m *Model) IsEnum(name string) bool

func (*Model) IsOperation

func (m *Model) IsOperation(name string) bool

func (*Model) Operation

func (m *Model) Operation(name string) (*Operation, error)

func (*Model) OperationEntities

func (m *Model) OperationEntities() ([]*Entity, error)

func (*Model) OperationParameters

func (m *Model) OperationParameters() map[*Operation][]*Parameter

func (*Model) OperationsByAction added in v0.3.0

func (m *Model) OperationsByAction(actions ...Action) []*Operation

func (*Model) PluralName

func (m *Model) PluralName() string

type Operation

type Operation struct {
	Name          string           `hcl:"name,label"`
	Description   *string          `hcl:"description,optional"`
	Action        Action           `hcl:"action,optional"`
	Method        Method           `hcl:"method"`
	Path          string           `hcl:"path"`
	Example       *string          `hcl:"example,optional"`
	Parameters    []*Parameter     `hcl:"parameter,block"`
	PathVariables []*PathVariable  `hcl:"path_variable,block"`
	Request       *EntityReference `hcl:"request,block"`
	Response      *EntityReference `hcl:"response,block"`
}

type Parameter

type Parameter struct {
	Name        string     `hcl:"name,label"`
	Description *string    `hcl:"description,optional"`
	Type        string     `hcl:"type"`
	Array       *bool      `hcl:"array,optional"`
	RawExample  *cty.Value `hcl:"example,optional"`
}

func (*Parameter) Example

func (p *Parameter) Example() (any, error)

type PathVariable

type PathVariable struct {
	Name        string     `hcl:"name,label"`
	Description *string    `hcl:"description,optional"`
	Type        string     `hcl:"type"`
	RawExample  *cty.Value `hcl:"example"`
}

func (*PathVariable) Example

func (p *PathVariable) Example() (any, error)

Jump to

Keyboard shortcuts

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