oasgen

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2023 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OasGenCmd = &cli.Command{
	Name:  "oasgen",
	Usage: "a tool for generate woocoo web code from OpenAPI 3 specifications",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:     "config",
			Value:    "oasgen.yaml",
			Aliases:  []string{"c"},
			Usage:    "configuration file",
			Required: true,
		},
		&cli.StringSliceFlag{
			Name:    "template",
			Aliases: []string{"t"},
			Usage:   "external templates to execute",
		},
	},
	Action: func(c *cli.Context) (err error) {
		var opts []Option
		for _, tmpl := range c.StringSlice("template") {
			typ := "dir"
			if parts := strings.SplitN(tmpl, "=", 2); len(parts) > 1 {
				typ, tmpl = parts[0], parts[1]
			}
			switch typ {
			case "dir":
				opts = append(opts, TemplateDir(tmpl))
			case "file":
				opts = append(opts, TemplateFiles(tmpl))
			}
		}
		cfg := &codegen.Config{}
		cnfPath := c.String("config")
		err = LoadConfig(cfg, cnfPath)
		if err != nil {
			return err
		}
		return Generate(cfg.OpenAPISchema, cfg, opts...)
	},
}

Functions

func Generate

func Generate(schemaPath string, cfg *codegen.Config, options ...Option) error

func LoadConfig

func LoadConfig(cfg *codegen.Config, filename string) (err error)

LoadConfig reads the openapi3 config file

func LoadGraph

func LoadGraph(schemaPath string, cfg *codegen.Config) (*codegen.Graph, error)

LoadGraph loads the schema package from the given schema path, and constructs a *gen.Graph.

Types

type Option

type Option func(*codegen.Config) error

func TemplateDir

func TemplateDir(path string) Option

TemplateDir parses the template definitions from the files in the directory and associates the resulting templates with codegen templates.

func TemplateFiles

func TemplateFiles(filenames ...string) Option

TemplateFiles parses the named files and associates the resulting templates with codegen templates.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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