generate

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2020 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateModels

func GenerateModels(targetFilepath string, templateFilepath string, rootDir string) error

GenerateModels parses the magma-gen-meta key of the given swagger YML file, copies the files that the target file depends on into the current working directory, shells out to `swagger generate models`, then cleans up the dependency files.

func ParseSwaggerDependencyTree

func ParseSwaggerDependencyTree(rootFilepath string, rootDir string) (map[string]MagmaSwaggerConfig, error)

ParseSwaggerDependencyTree parses the entire dependency tree of a magma swagger spec file specified by the rootFilepath parameter. The returned value maps between the absolute specified dependency filepath and the parsed struct for the dependency file.

func RewriteGeneratedRefs

func RewriteGeneratedRefs(targetFilepath string, rootDir string) error

RewriteGeneratedRefs rewrites the Go files generated by go-swagger by updating the type identifiers for generated types owned by dependency swagger specs to the packages where those types are generated into.

This function will add appropriate imports and rewrite all references. After rewriting the generated files, all files for types that aren't owned by the target swagger spec will be removed from the output directory as well.

func StripAndWriteSwaggerConfigs

func StripAndWriteSwaggerConfigs(allConfigs map[string]MagmaSwaggerConfig) error

Types

type MagmaGenMeta

type MagmaGenMeta struct {
	// GoPackage is the target Go package that the models defined in this spec
	// will be generated into (including the trailing `models`)
	// This will be referenced by the tool when adding imports to generated
	// files during the modification step of generation.
	GoPackage string `yaml:"go-package"`

	// OutputDir specifies the desired output directory relative to MAGMA_ROOT
	// that the models in this package should be generated into.
	OutputDir string `yaml:"output-dir"`

	// Dependencies is a list of swagger spec files that this file references.
	// This should be a list of filepaths relative to MAGMA_ROOT.
	Dependencies []string

	// TempGenFilename will be the filename that the swaggergen tool renames
	// this spec file to when copying it into directories of dependent
	// specs during generation. Dependent specs should reference definitions
	// in this spec by referencing from this filename.
	TempGenFilename string `yaml:"temp-gen-filename"`

	// Types is a list of Go struct names and generated filenames that this
	// spec file produces. This will be referenced by the tool when replacing
	// references.
	Types []MagmaGenType
}

type MagmaGenType

type MagmaGenType struct {
	GoStructName string `yaml:"go-struct-name"`
	Filename     string
}

type MagmaSwaggerConfig

type MagmaSwaggerConfig struct {
	Swagger      string
	MagmaGenMeta MagmaGenMeta `yaml:"magma-gen-meta"`
	Info         struct {
		Title       string
		Description string
		Version     string
	}
	BasePath    string `yaml:"basePath"`
	Consumes    []string
	Produces    []string
	Schemes     []string
	Tags        []TagDefinition
	Paths       map[string]interface{}
	Responses   map[string]interface{}
	Parameters  map[string]interface{}
	Definitions map[string]interface{}
}

MagmaSwaggerConfig is the Go struct version of our custom Swagger spec file. The only difference is the magma-gen-meta field, which specifies dependencies (other swagger specs that the spec has refs to), a desired filename that this file should be ref'd with from dependent files, and a list of Go struct types and filenames that this file produces when models are generated.

func (MagmaSwaggerConfig) ToSwaggerConfig

func (msc MagmaSwaggerConfig) ToSwaggerConfig() SwaggerConfig

type SwaggerConfig

type SwaggerConfig struct {
	Swagger string
	Info    struct {
		Title       string
		Description string
		Version     string
	}
	BasePath    string `yaml:"basePath"`
	Consumes    []string
	Produces    []string
	Schemes     []string
	Tags        []TagDefinition
	Paths       map[string]interface{}
	Responses   map[string]interface{}
	Parameters  map[string]interface{}
	Definitions map[string]interface{}
}

SwaggerConfig is the Go struct version of a OAI/Swagger 2.0 YAML spec file.

type TagDefinition

type TagDefinition struct {
	Description string
	Name        string
}

Jump to

Keyboard shortcuts

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