generator

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyResponseOverlay

func ApplyResponseOverlay(response Response, data interface{}) error

ApplyResponseOverlay expects data to be passed by reference. The response overlay will be applied by merging/overriding data.

func ExpandOperationIDs

func ExpandOperationIDs(document *loads.Document)

ExpandOperationIDs the operationId field can be omitted in the spec. Codegen tools will automatically generate a default value for this field but go-openapi does not. ExpandOperationIDs will expand empty operationId fields into a useful name for usage in error/logging.

func ExpandPaths

func ExpandPaths(document *loads.Document, basePath string)

ExpandPaths modifies all the paths in the openapi document by prefixing them with the basePath

func StubSchema

func StubSchema(schema spec.Schema) interface{}

StubSchema returns a struct that matches the openapi schema with values filled with randomly generated data

Types

type Operation

type Operation struct {
	Responses map[int]Response `yaml:"responses"`
}

type Overlay

type Overlay struct {
	Paths map[string]PathItem `yaml:"paths"`
}

func EmptyOverlay

func EmptyOverlay() Overlay

EmptyOverlay is used when the user doesn't provide and overlay file. it's just used inplace of a nil value.

func LoadOverlayFile

func LoadOverlayFile(path string) (*Overlay, error)

LoadOverlayFile reads an overlay.yaml file into an Overlay struct

func (*Overlay) FindResponse

func (overlay *Overlay) FindResponse(path string, method string, statusCode int) (*Response, error)

type PathItem

type PathItem struct {
	Get     *Operation `yaml:"get,omitempty"`
	Put     *Operation `yaml:"put,omitempty"`
	Post    *Operation `yaml:"post,omitempty"`
	Patch   *Operation `yaml:"patch,omitempty"`
	Options *Operation `yaml:"options,omitempty"`
	Head    *Operation `yaml:"head,omitempty"`
}

type Response

type Response struct {
	Content string `yaml:"content"`
}

type StubGenerator

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

StubGenerator is the main type used to interact with this library's feature set

func NewStubGenerator

func NewStubGenerator(urlOrPath string, options StubGeneratorOptions) (*StubGenerator, error)

NewStubGenerator loads an OpenAPI spec from the given url/path and returns a StubGenerator

func (*StubGenerator) FindOperation

func (stub *StubGenerator) FindOperation(httpPath string, httpMethod string) (*spec.Operation, error)

FindOperation returns the best matching OpenAPI operation from the Spec given an HTTP Request

func (*StubGenerator) FindResponse

func (stub *StubGenerator) FindResponse(operation *spec.Operation) (*spec.Response, *int, error)

FindResponse returns either the default response from an operation or the response with the lowest HTTP status code (i.e. success codes over error codes)

func (*StubGenerator) StubResponse

func (stub *StubGenerator) StubResponse(path string, method string) (interface{}, error)

StubResponse returns data that matches the schema for a given Operation in the OpenAPI spec. The Operation is determined by a path and method

type StubGeneratorOptions

type StubGeneratorOptions struct {
	Overlay  string
	BasePath string
}

StubGeneratorOptions that can configure the stub generator

Jump to

Keyboard shortcuts

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