gen_sdk

package
v1.9.11 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const GoProxyEnvKey = "GOPROXY"

GoProxyEnvKey with the environment variable name that defines the GOPROXY preferences.

View Source
const (
	// PackagePlaceHolder is the package name placeholder
	PackagePlaceHolder = "github.com/kubevela/vela-go-sdk"
)

Variables

View Source
var (
	//go:embed openapi-generator/templates
	// Templates contains different template files for different languages
	Templates embed.FS
	// SupportedLangs is supported languages
	SupportedLangs = map[string]bool{"go": true}
	//go:embed _scaffold
	// Scaffold is scaffold files for different languages
	Scaffold embed.FS
	// ScaffoldDir is scaffold dir name
	ScaffoldDir = "_scaffold"
)
View Source
var (
	// DefinitionKindToPascal is the map of definition kind to pascal case
	DefinitionKindToPascal = map[string]string{
		v1beta1.ComponentDefinitionKind:    "Component",
		v1beta1.TraitDefinitionKind:        "Trait",
		v1beta1.WorkflowStepDefinitionKind: "WorkflowStep",
		v1beta1.PolicyDefinitionKind:       "Policy",
	}
	// DefinitionKindToBaseType is the map of definition kind to base type
	DefinitionKindToBaseType = map[string]string{
		v1beta1.ComponentDefinitionKind:    "ComponentBase",
		v1beta1.TraitDefinitionKind:        "TraitBase",
		v1beta1.WorkflowStepDefinitionKind: "WorkflowStepBase",
		v1beta1.PolicyDefinitionKind:       "PolicyBase",
	}
	// DefinitionKindToStatement is the map of definition kind to statement
	DefinitionKindToStatement = map[string]*j.Statement{
		v1beta1.ComponentDefinitionKind:    j.Qual("common", "ApplicationComponent"),
		v1beta1.TraitDefinitionKind:        j.Qual("common", "ApplicationTrait"),
		v1beta1.WorkflowStepDefinitionKind: j.Qual("v1beta1", "WorkflowStep"),
		v1beta1.PolicyDefinitionKind:       j.Qual("v1beta1", "AppPolicy"),
	}
)
View Source
var (

	// LangArgsRegistry is used to store the argument info
	LangArgsRegistry = map[string]map[langArgKey]LangArg{}
)

Functions

This section is empty.

Types

type CUEType

type CUEType string

CUEType is the possible types in CUE

type GenMeta

type GenMeta struct {
	Output       string
	APIDirectory string
	IsSubModule  bool
	Lang         string
	Package      string
	Template     string
	File         []string
	InitSDK      bool
	Verbose      bool

	LangArgs LanguageArgs
	// contains filtered or unexported fields
}

GenMeta stores the metadata for generator.

func (*GenMeta) CreateScaffold

func (meta *GenMeta) CreateScaffold() error

CreateScaffold will create a scaffold for the given language. It will copy all files from embedded scaffold/{meta.Lang} to meta.Output.

func (*GenMeta) Init

func (meta *GenMeta) Init(c common.Args, langArgs []string) (err error)

Init initializes the generator. It will validate the param, analyze the CUE files, read them to memory, mkdir for output.

func (*GenMeta) PrepareGeneratorAndTemplate

func (meta *GenMeta) PrepareGeneratorAndTemplate() error

PrepareGeneratorAndTemplate will make a copy of the embedded openapi-generator-cli and templates/{meta.Lang} to local

func (*GenMeta) Run

func (meta *GenMeta) Run() error

Run will generally do two thing: 1. Generate OpenAPI schema from cue files 2. Generate code from OpenAPI schema

func (*GenMeta) SetDefinition

func (meta *GenMeta) SetDefinition(defName, defKind string)

SetDefinition sets definition name and kind

type Generator

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

Generator is used to generate SDK code from CUE template for one language.

func NewModifiableGenerator

func NewModifiableGenerator(meta *GenMeta) *Generator

NewModifiableGenerator returns a new Generator with modifiers

func (*Generator) GenOpenAPISchema

func (g *Generator) GenOpenAPISchema(val *value.Value) error

GenOpenAPISchema generates OpenAPI json schema from cue.Instance

func (*Generator) GenerateCode

func (g *Generator) GenerateCode() (err error)

GenerateCode will call openapi-generator to generate code and modify it

func (*Generator) GetDefinitionValue

func (g *Generator) GetDefinitionValue(cueBytes []byte) (*value.Value, string, string, error)

GetDefinitionValue returns a value.Value definition name, definition kind from cue bytes

type GoDefModifier

type GoDefModifier struct {
	*GenMeta
	// contains filtered or unexported fields
}

GoDefModifier is the Modifier for golang, modify code for each definition

func (*GoDefModifier) Modify

func (m *GoDefModifier) Modify() error

Modify the modification of generated code

func (*GoDefModifier) Name

func (m *GoDefModifier) Name() string

Name the name of modifier

type GoModuleModifier

type GoModuleModifier struct {
	*GenMeta
	// contains filtered or unexported fields
}

GoModuleModifier is the Modifier for golang, modify code for each module which contains multiple definitions

func (*GoModuleModifier) Modify

func (m *GoModuleModifier) Modify() error

Modify implements Modifier

func (*GoModuleModifier) Name

func (m *GoModuleModifier) Name() string

Name the name of modifier

type LangArg

type LangArg struct {
	Name    langArgKey
	Desc    string
	Default string
}

LangArg is language-specific argument.

type LanguageArgs

type LanguageArgs interface {
	Get(key langArgKey) string
	Set(key langArgKey, value string)
}

LanguageArgs is used to store the arguments for the language.

func NewLanguageArgs

func NewLanguageArgs(lang string, langArgs []string) (LanguageArgs, error)

NewLanguageArgs parses the language arguments and returns a LanguageArgs.

type Modifier

type Modifier interface {
	Modify() error
	Name() string
}

Modifier is used to modify the generated code.

Directories

Path Synopsis
_scaffold

Jump to

Keyboard shortcuts

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