gen_sdk

package
v1.8.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

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"),
	}
)

Functions

This section is empty.

Types

type GenMeta

type GenMeta struct {
	Output   string
	Lang     string
	Package  string
	Template string
	File     []string
	InitSDK  bool
	Verbose  bool
	// 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) (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

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, error)

GetDefinitionValue returns a value.Value from cue bytes

type GoModifier

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

GoModifier is the Modifier for golang

func (*GoModifier) Modify

func (m *GoModifier) Modify() error

Modify the modification of generated code

func (*GoModifier) Name

func (m *GoModifier) Name() string

Name the name of modifier

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