astra

package module
v1.23.10 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 19 Imported by: 0

README

Astra

AST-based specification for Go APIs

An automatic Go type extractor for web services with very little additional configuration

Astra is a tool that extracts types from web services without any additional configuration for the handlers and outputs them in various formats. It is intended to be used as a library with your code.

The idea stems from not having to define any additional comments or code duplication to export your types to be used in other systems, not violating the DRY (Don't Repeat Yourself) principle.

For example, if you had a Go backend that used the Gin framework, you would have to define the types in the handler function, and then define them again in the OpenAPI specification. This is not only time consuming, but also violates the DRY principle. Whereas our solution, you'd only have to define the types once, and then use Astra to extract them from the handlers and output them to the OpenAPI specification, which you could host using Swagger UI or use them to generate client code.

Features

The key features of Astra are:

  • Extract types from web services
  • Read types from files
  • Follow through different functions to extract types
  • Extract types from any packages from the dependency tree
  • Adapt to different coding styles
  • Read the entirety of the main package (by extracting to a temporary directory $GOPATH/.astra/astramain) to extract types
  • Support for different input and output formats
  • Support for CLI (CI/CD)
  • Support for denying functions from being parsed
  • Support for custom logging
  • Support for custom status codes they must be defined as constants/only defined once (http.StatusX is perfect, or 200)
  • Support for comments in struct fields and above named types
  • Support for enum-like named types (e.g. type Status string and const (StatusOK Status = "OK") etc.) to be parsed as enums if they are defined in the same package!

Supported Formats

Currently supported input formats
Currently supported output formats

Usage

If you have Go module support, then simply add this import to your configuration:

import "github.com/Mrzrb/astra"

and run the appropriate go commands to pull in the dependency.

Otherwise, install the package using the following command:

$ go get -u github.com/Mrzrb/astra

We recommend using the OpenAPI specification as the output format, as it is the most widely used format for describing RESTful APIs. To use it, you need to import the following package:

package main

import (
	"github.com/gin-gonic/gin"
	"github.com/Mrzrb/astra"
	"github.com/Mrzrb/astra/inputs"
	"github.com/Mrzrb/astra/outputs"
)

func main() {
	r := gin.Default()

	r.GET("/posts", GetPosts)
	r.GET("/posts/:id", GetPost)
	r.POST("/posts", CreatePost)
	r.PUT("/posts/:id", UpdatePost)
	r.DELETE("/posts/:id", DeletePost)

	r.GET("/health", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"status": "ok",
		})
	})

	gen := astra.New(inputs.WithGinInput(r), outputs.WithOpenAPIOutput("openapi.generated.yaml"))

	// For OpenAPI to work, we need to define a configuration, which contains the title, version and description amongst other important information
	config := astra.Config{
		Title:   "Example API",
		Version: "1.0.0",
		Host:    "localhost",
		Port:    8000,
	}
	
	// Or you can use our config builder, which will set the host to "localhost" by default, and will validate the configuration to test if it is valid.
	config, err := astra.NewConfigBuilder().SetTitle("Example API").SetVersion("1.0.0").SetPort(8000).SetSecure(false).Build()
	if err != nil {
		panic(err)
	}

	// Either way, you need to set the config for the OpenAPI generator to use
	gen.SetConfig(config)
	
	
	err = gen.Parse()
	if err != nil {
		panic(err)
	}

	err = r.Run(":8000")
	if err != nil {
		panic(err)
	}
}
CLI (CI/CD)

Astra also has a method for running the program from the command line, which is useful for CI/CD pipelines. To use it, follow the instructions in the CLI documenation.

Denying

Astra can also deny certain functions from being parsed. This is useful if you have a function that you don't want to be parsed, such as a function that is used for testing. To use this, follow the instructions in the denying documentation.

Logging

We use ZeroLog for logging, which is a fast and lightweight logging library. By default we have info level logging configured, but to specify debug, you can add a configuration option to the New function

astra.New(...(previous configuration)..., astra.WithCustomLogLevel("debug"))

Or if you wanted to set a new logger function:

import "github.com/rs/zerolog/log"

logger := log.With().Caller().Logger()
astra.New(...(previous configuration)..., astra.WithCustomLogger(logger))

More information can be found in the logging documentation.

How it works

Astra utilises the inbuilt Go AST (Abstract Syntax Tree) to parse the source code of your project. It then extracts the types from the source code and outputs them in the desired format. The documentation for the AST can be found here. The AST is a tree representation of the source code, which can be traversed to extract the types. We can then utilise the Go tools packages library to extract the types from the source code of the packages wherever they are located on the dependency tree.

We have methods to extract types from the following:

  • Functions in your code
  • Functions in the dependency tree
  • Functions in the main package
  • Anywhere that utilises the gin.Context type
  • Functions from inline functions (but it has to be set inside the function where you specify your routes)

There is more information in the how it works documentation

Upcoming features
  • Extract types from other web frameworks as inputs (e.g. Echo, Fiber, etc.)
  • Add support for more output formats (e.g. TypeScript interfaces/classes etc.)
  • Add more unit tests and more documentation
  • Test more edge cases (please report any issues you find!)

Issue Reporting

Naturally a project that has to adapt to so many people's coding styles will have some issues. If you find any, please report them in the issues section of this repository.

Please try to be as specific as possible,

We will try to fix them as soon as possible.

Contributing

We aim to welcome contributions to this project, will provide further information in due course. This project uses Conventional Commits for commit messages.

Developed and maintained by the LS6 Events Team

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConfigNotFound     = errors.New("config not found")
	ErrConfigPortRequired = errors.New("config port is required")

	ErrInputModeNotFound = errors.New("input mode not found")

	ErrOutputModeNotFound          = errors.New("output mode not found")
	ErrOutputFilePathRequired      = errors.New("output file path is required")
	ErrOutputDirectoryPathRequired = errors.New("output directory path is required")
)

This file contains all the errors that can be returned by the generator.

View Source
var AcceptedTypes = []string{
	"nil",
	"string",
	"int",
	"int8",
	"int16",
	"int32",
	"int64",
	"uint",
	"uint8",
	"uint16",
	"uint32",
	"uint64",
	"float",
	"float32",
	"float64",
	"bool",
	"byte",
	"rune",
	"struct",
	"map",
	"slice",
	"any",
	"file",
}

AcceptedTypes is a list of all accepted types for the astra package. Everything else is considered a type that has to be processed.

View Source
var PredefinedTypeMap = map[string]TypeFormat{
	"string": {
		Type: "string",
	},
	"int": {
		Type:   "integer",
		Format: "int32",
	},
	"int8": {
		Type:   "integer",
		Format: "int8",
	},
	"int16": {
		Type:   "integer",
		Format: "int16",
	},
	"int32": {
		Type:   "integer",
		Format: "int32",
	},
	"int64": {
		Type:   "integer",
		Format: "int64",
	},
	"uint": {
		Type:   "integer",
		Format: "uint",
	},
	"uint8": {
		Type:   "integer",
		Format: "uint8",
	},
	"uint16": {
		Type:   "integer",
		Format: "uint16",
	},
	"uint32": {
		Type:   "integer",
		Format: "uint32",
	},
	"uint64": {
		Type:   "integer",
		Format: "uint64",
	},
	"float32": {
		Type:   "number",
		Format: "float32",
	},
	"float64": {
		Type:   "number",
		Format: "float64",
	},
	"bool": {
		Type: "boolean",
	},
	"byte": {
		Type:   "string",
		Format: "byte",
	},
	"rune": {
		Type:   "string",
		Format: "rune",
	},
	"struct": {
		Type: "object",
	},
	"map": {
		Type: "object",
	},
	"slice": {
		Type: "array",
	},
	"any": {
		Type: "",
	},
	"nil": {
		Type: "",
	},

	"time.Time": {
		Type:   "string",
		Format: "date-time",
	},
	"github.com/google/uuid.UUID": {
		Type:   "string",
		Format: "uuid",
	},

	"file": {
		Type:   "string",
		Format: "binary",
	},
}

PredefinedTypeMap is the map of the standard go types that are accepted by OpenAPI. It contains the go type as a string and the corresponding OpenAPI type as the value - also including the format.

Functions

func BindingTagToContentTypes

func BindingTagToContentTypes(bindingTag astTraversal.BindingTagType) []string

func Collector added in v1.23.4

func Collector(rootPath string) map[string]MethodInfo

func Contains

func Contains[S ~[]E, E comparable](s S, v E) bool

func ContentTypeToBindingTag

func ContentTypeToBindingTag(contentType string) astTraversal.BindingTagType

func ExtraMethodAndName added in v1.23.4

func ExtraMethodAndName(testString string) (string, string, error)

func ExtractBindingTags

func ExtractBindingTags(fields map[string]Field) (bindingTags []astTraversal.BindingTagType, uniqueBindings bool)

func Index

func Index[S ~[]E, E comparable](s S, v E) int

func IsAcceptedType

func IsAcceptedType(t string) bool

func ParseAndStoreMethods added in v1.23.4

func ParseAndStoreMethods(filename string) map[string]MethodInfo

Types

type BodyParam

type BodyParam struct {
	Name        string `json:"name,omitempty" yaml:"name,omitempty"`
	Field       Field  `json:"type,omitempty" yaml:"type,omitempty"`
	ContentType string `json:"contentType,omitempty" yaml:"contentType,omitempty"`
	IsRequired  bool   `json:"isRequired,omitempty" yaml:"isRequired,omitempty"`
	IsArray     bool   `json:"isArray,omitempty" yaml:"isArray,omitempty"`
	IsMap       bool   `json:"isMap,omitempty" yaml:"isMap,omitempty"`

	IsBound bool `json:"isBound,omitempty" yaml:"isBound,omitempty"` // I.e. is a struct reference
}

type CLIMode

type CLIMode string

CLIMode is the mode the CLI is running in.

const (
	CLIModeNone    CLIMode = ""        // Not running in CLI mode
	CLIModeSetup   CLIMode = "setup"   // Running in setup mode - used in the project code to setup the routes
	CLIModeBuilder CLIMode = "builder" // Running in builder mode - used in the project code to build the routes and generate the types (this is not needed to be used by other developers, the CLI will use this mode)
)

type Config

type Config struct {
	Title       string  `json:"title"`
	Description string  `json:"description"`
	Version     string  `json:"version"`
	Contact     Contact `json:"contact"`
	License     License `json:"license"`

	Secure   bool   `json:"secure"`
	Host     string `json:"host"`
	BasePath string `json:"basePath"`
	Port     int    `json:"port"`
}

Config is the configuration for the generator. It matches very closely to the OpenAPI specification.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration. It will also set default values for some fields.

type ConfigBuilder

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

func NewConfigBuilder

func NewConfigBuilder() *ConfigBuilder

func (*ConfigBuilder) Build

func (c *ConfigBuilder) Build() (*Config, error)

func (*ConfigBuilder) SetBasePath

func (c *ConfigBuilder) SetBasePath(basePath string) *ConfigBuilder

func (*ConfigBuilder) SetContact

func (c *ConfigBuilder) SetContact(contact Contact) *ConfigBuilder

func (*ConfigBuilder) SetDescription

func (c *ConfigBuilder) SetDescription(description string) *ConfigBuilder

func (*ConfigBuilder) SetHost

func (c *ConfigBuilder) SetHost(host string) *ConfigBuilder

func (*ConfigBuilder) SetLicense

func (c *ConfigBuilder) SetLicense(license License) *ConfigBuilder

func (*ConfigBuilder) SetPort

func (c *ConfigBuilder) SetPort(port int) *ConfigBuilder

func (*ConfigBuilder) SetSecure

func (c *ConfigBuilder) SetSecure(secure bool) *ConfigBuilder

func (*ConfigBuilder) SetTitle

func (c *ConfigBuilder) SetTitle(title string) *ConfigBuilder

func (*ConfigBuilder) SetVersion

func (c *ConfigBuilder) SetVersion(version string) *ConfigBuilder

type Contact

type Contact struct {
	Name  string `json:"name"`
	URL   string `json:"url"`
	Email string `json:"email"`
}

type ContextFuncBuilder

type ContextFuncBuilder struct {
	Route     *Route
	Traverser *astTraversal.CallExpressionTraverser
	// contains filtered or unexported fields
}

func NewContextFuncBuilder

func NewContextFuncBuilder(route *Route, traverser *astTraversal.CallExpressionTraverser) *ContextFuncBuilder

func (*ContextFuncBuilder) Build

func (c *ContextFuncBuilder) Build(mapper func(*Route, []any) (*Route, error)) (*Route, error)

func (*ContextFuncBuilder) ExpressionResult

func (c *ContextFuncBuilder) ExpressionResult() *ContextFuncBuilder

func (*ContextFuncBuilder) Ignored

func (c *ContextFuncBuilder) Ignored() *ContextFuncBuilder

func (*ContextFuncBuilder) StatusCode

func (c *ContextFuncBuilder) StatusCode() *ContextFuncBuilder

func (*ContextFuncBuilder) Value

type CustomFunc

type CustomFunc func(contextVarName string, contextFuncBuilder *ContextFuncBuilder) (*Route, error)

type Field

type Field struct {
	Package string `json:"package,omitempty" yaml:"package,omitempty"`
	Type    string `json:"type,omitempty" yaml:"type,omitempty"`
	Name    string `json:"name,omitempty" yaml:"name,omitempty"`

	EnumValues []any `json:"enumValues,omitempty" yaml:"enumValues,omitempty"`

	IsRequired bool `json:"isRequired,omitempty" yaml:"isRequired,omitempty"`
	IsEmbedded bool `json:"isEmbedded,omitempty" yaml:"isEmbedded,omitempty"`

	SliceType string `json:"sliceType,omitempty" yaml:"sliceType,omitempty"`

	ArrayType   string `json:"arrayType,omitempty" yaml:"arrayType,omitempty"`
	ArrayLength int64  `json:"arrayLength,omitempty" yaml:"arrayLength,omitempty"`

	MapKeyPackage string `json:"mapKeyPackage,omitempty" yaml:"mapKeyPackage,omitempty"`
	MapKeyType    string `json:"mapKeyType,omitempty" yaml:"mapKeyType,omitempty"`
	MapValueType  string `json:"mapValueType,omitempty" yaml:"mapValueType,omitempty"`

	StructFields              map[string]Field              `json:"structFields,omitempty" yaml:"structFields,omitempty"`
	StructFieldBindingTags    astTraversal.BindingTagMap    `json:"structFieldBindingTags,omitempty" yaml:"structFieldBindingTags,omitempty"`
	StructFieldValidationTags astTraversal.ValidationTagMap `json:"structFieldValidationTags,omitempty" yaml:"structFieldValidationTags,omitempty"`

	Doc string `json:"doc,omitempty" yaml:"doc,omitempty"`
}

Field is a field in a struct. It contains the package, type, and name of the field (the type is slice, map or struct in the case of a slice, map or struct). It also contains whether the field is required and whether it is embedded. If the field is a slice, it contains the type of the slice (package is the package of the type). If the field is a map, it contains the key and value types of the map (and the key package, we treat the package as the value package). If the field is a struct, it contains the fields of the struct.

func AddComponent

func AddComponent(prev []Field, n ...Field) []Field

AddComponent adds a component to a slice of components if it doesn't already exist. It uses the field type and package to determine if the component already exists.

func ParseResultToField

func ParseResultToField(result astTraversal.Result) Field

ParseResultToField changes a result from the AST traversal to a local field.

type IOConfiguration

type IOConfiguration map[IOConfigurationKey]any

type IOConfigurationKey

type IOConfigurationKey string
const (
	IOConfigurationKeyFilePath      IOConfigurationKey = "filePath"
	IOConfigurationKeyDirectoryPath IOConfigurationKey = "directoryPath"
)

type Input

type Input struct {
	Mode         InputMode       `json:"mode"`
	CreateRoutes ServiceFunction `json:"-"`
	ParseRoutes  ServiceFunction `json:"-"`
}

Input is the input for the generator.

type InputMode

type InputMode string

type License

type License struct {
	Name string `json:"name"`
	URL  string `json:"url"`
}

type MethodInfo added in v1.23.4

type MethodInfo struct {
	MethodName     string
	FileName       string
	Line           int
	MethodReceiver string
	PkgName        string
}

func (*MethodInfo) Id added in v1.23.9

func (m *MethodInfo) Id() string

type Option

type Option func(*Service)

Option is a function that can be used to configure the generator.

func WithConfig

func WithConfig(config *Config) Option

WithConfig sets the configuration for the generator in option pattern.

func WithCustomFunc

func WithCustomFunc(customFunc CustomFunc) Option

func WithCustomLogLevel

func WithCustomLogLevel(level string) Option

WithCustomLogLevel enables the custom log level for the generator. This allows for easier debugging and controlling of logs.

func WithCustomLogger

func WithCustomLogger(logger zerolog.Logger) Option

WithCustomLogger enables the custom logger for the generator. It needs to pass in a zerolog.Logger.

func WithCustomTypeMapping

func WithCustomTypeMapping(customTypeMap map[string]TypeFormat) Option

WithCustomTypeMapping adds a custom type mapping to the predefined type map.

func WithCustomTypeMappingSingle

func WithCustomTypeMappingSingle(key string, valueType string, valueFormat string) Option

WithCustomTypeMappingSingle adds a custom type mapping to the predefined type map.

func WithCustomWorkDir

func WithCustomWorkDir(wd string) Option

WithCustomWorkDir is an option to set the working directory of the service to a custom directory.

func WithPathDenyList

func WithPathDenyList(denyList string) Option

func WithPathDenyListFunc

func WithPathDenyListFunc(denyList func(string) bool) Option

func WithPathDenyListRegex

func WithPathDenyListRegex(regex *regexp.Regexp) Option

type Output

type Output struct {
	Mode          OutputMode      `json:"mode"`
	Generate      ServiceFunction `json:"-"`
	Configuration IOConfiguration `json:"configuration"`
}

Output is the output for the generator It takes in a configuration object to allow the caching mechanism to store the file paths for the outputs.

type OutputMode

type OutputMode string

type Param

type Param struct {
	Name       string `json:"name,omitempty" yaml:"name,omitempty"`
	Field      Field  `json:"type,omitempty" yaml:"type,omitempty"`
	IsRequired bool   `json:"isRequired,omitempty" yaml:"isRequired,omitempty"`
	IsArray    bool   `json:"isArray,omitempty" yaml:"isArray,omitempty"`
	IsMap      bool   `json:"isMap,omitempty" yaml:"isMap,omitempty"`

	IsBound bool `json:"isBound,omitempty" yaml:"isBound,omitempty"` // I.e. is a struct reference.
}

Param is a parameter for a route. It contains the name, type, and whether it is required. It also contains an IsBound field, which is used to denote whether the param is a struct reference.

type Processable

type Processable struct {
	Name string
	Pkg  string
}

Processable is a struct that is processable by the astra package. It just contains the name of the type and the package it came from.

type ReturnType

type ReturnType struct {
	StatusCode  int    `json:"statusCode,omitempty" yaml:"statusCode,omitempty"`
	ContentType string `json:"contentType,omitempty" yaml:"contentType,omitempty"`
	Field       Field  `json:"field,omitempty" yaml:"field,omitempty"`
}

ReturnType is a return type for a route. It contains the status code and the field that is returned.

func AddReturnType

func AddReturnType(prev []ReturnType, n ...ReturnType) []ReturnType

AddReturnType adds a return type to a slice of return types if it doesn't already exist. It uses the field type, package and status code to determine if the return type already exists.

type Route

type Route struct {
	Handler     string       `json:"handler" yaml:"handler"`
	File        string       `json:"file" yaml:"file"`
	LineNo      int          `json:"lineNo" yaml:"lineNo"`
	Method      string       `json:"method" yaml:"method"`
	Path        string       `json:"path" yaml:"path"`
	PathParams  []Param      `json:"params,omitempty" yaml:"params,omitempty"` // for now, we use :param in the path to denote a required path param, and *param to denote an optional path param.
	QueryParams []Param      `json:"queryParams,omitempty" yaml:"queryParams,omitempty"`
	Body        []BodyParam  `json:"body,omitempty" yaml:"body,omitempty"`
	ReturnTypes []ReturnType `json:"returnTypes,omitempty" yaml:"returnTypes,omitempty"`
	Doc         string       `json:"doc,omitempty" yaml:"doc,omitempty"`
	OperationID string       `json:"operationId,omitempty" yaml:"operationId,omitempty"`

	RequestHeaders  []Param `json:"requestHeaders,omitempty" yaml:"requestHeaders,omitempty"`
	ResponseHeaders []Param `json:"responseHeaders,omitempty" yaml:"responseHeaders,omitempty"`
}

Route is a route in the service and all of its potential options.

type Service

type Service struct {
	Inputs  []Input  `json:"inputs" yaml:"inputs"`
	Outputs []Output `json:"outputs" yaml:"outputs"`

	Log zerolog.Logger `json:"-"`

	Config *Config `json:"config" yaml:"config"`

	Routes []Route `json:"routes" yaml:"routes"`

	Components    []Field `json:"components" yaml:"components"`
	AstMethodInfo map[string]MethodInfo

	WorkDir string `json:"-" yaml:"-"`

	CacheEnabled bool    `json:"-"`
	CachePath    string  `json:"-"`
	CLIMode      CLIMode `json:"-"`

	PathDenyList []func(string) bool `json:"-" yaml:"-"`

	CustomFuncs []CustomFunc `json:"-" yaml:"-"`

	// CustomTypeMapping is a map of custom types to their OpenAPI type and format
	CustomTypeMapping map[string]TypeFormat `json:"custom_type_mapping" yaml:"custom_type_mapping"`
	// contains filtered or unexported fields
}

Service is the main struct for the generator.

func New

func New(opts ...Option) *Service

New creates a new generator service. It takes in a list of options that can be used to configure the generator. It will also setup the logger for the generator and setup the slices that are used to store the routes, inputs, outputs and components.

func (*Service) AddRoute

func (s *Service) AddRoute(route Route)

AddRoute adds a route to the service.

func (*Service) Cache

func (s *Service) Cache() error

Cache the service in a file.

func (*Service) Clean

func (s *Service) Clean() error

Clean cleans up the structs. At the moment it only changes the package name of the main package to "main". It also handles the "special" types. It also caches the service after cleaning.

func (*Service) ClearCache

func (s *Service) ClearCache() error

ClearCache Clear the cache file.

func (*Service) CompleteParse

func (s *Service) CompleteParse() error

CompleteParse completes the parse by calling the ParseRoutes function, Process function, Clean function and Generate function. It will parse the routes from the files identified, process the found definitions, clean up the structs and generate the outputs. CompleteParse should be called after SetupParse.

func (*Service) CreateRoutes

func (s *Service) CreateRoutes() error

CreateRoutes creates routes from the inputs.

func (*Service) Generate

func (s *Service) Generate() error

Generate generates the outputs utilising the stored data in the service.

func (*Service) GetMainPackageName

func (s *Service) GetMainPackageName() (string, error)

GetMainPackageName returns the name of the temporary main package.

func (*Service) GetTypeMapping

func (s *Service) GetTypeMapping(key string, pkg string) (TypeFormat, bool)

GetTypeMapping returns the type mapping for the given key.

func (*Service) HandleSubstituteTypes

func (s *Service) HandleSubstituteTypes(component *Field)

HandleSubstituteTypes handles substitute types.

func (*Service) LoadCache

func (s *Service) LoadCache() error

LoadCache Load the service from a file cache. If the file does not exist, it will not return an error.

func (*Service) LoadCacheFromCustomPath

func (s *Service) LoadCacheFromCustomPath(cachePath string) error

LoadCacheFromCustomPath Load the service from a file cache. If the file does not exist, it will return an error. Requires the path to the cache file.

func (*Service) MoveTempOutputDir

func (s *Service) MoveTempOutputDir(dirPath, outputDir string) error

func (*Service) Parse

func (s *Service) Parse() error

Parse parses the inputs and generates the outputs. It will call the SetupParse function and then the CompleteParse function. It should be used if you don't intend to use the CLI.

func (*Service) ParseRoutes

func (s *Service) ParseRoutes() error

ParseRoutes iterates over the inputs and parses the routes from them. CreateRoutes should be called before ParseRoutes.

func (*Service) ReplaceRoute

func (s *Service) ReplaceRoute(route Route)

ReplaceRoute replaces a route in the service using the path and method as indexes.

func (*Service) SetConfig

func (s *Service) SetConfig(config *Config) *Service

SetConfig sets the configuration for the generator.

func (*Service) Setup

func (s *Service) Setup() error

Setup sets up the service by creating the temp dir and caching. Setup should be called before anything else in the service.

func (*Service) SetupParse

func (s *Service) SetupParse() error

SetupParse sets up the parse by calling the Setup function and then the CreateRoutes function. It will create the routes from the inputs but not parse them. SetupParse should be called before CompleteParse. SetupParse should be used if you are using the CLI or if you want to parse the routes yourself.

func (*Service) SetupTempOutputDir

func (s *Service) SetupTempOutputDir(dirPath string) (string, error)

func (*Service) Teardown

func (s *Service) Teardown() error

Teardown tears down the service by cleaning up the temp dir. Teardown should be called after everything else in the service.

type ServiceFunction

type ServiceFunction func(service *Service) error

ServiceFunction is the function used by the inputs/outputs to interact with the service.

type TypeFormat

type TypeFormat struct {
	Type   string
	Format string
}

TypeFormat is the types of the standard go types that are accepted by OpenAPI.

Jump to

Keyboard shortcuts

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