openapi3

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: GPL-3.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataResolver

type DataResolver struct {
	contract.EntityTrait
	Spec          *openapi3.Swagger
	Op            *Operation
	SpecResponses *openapi3.Responses
}

DataResolver provides spec data based on user input. OAS spec file may contain multiple definitions for everything, so this resolver helps to choose the right one among htem based on hints.

func NewDataResolver

func NewDataResolver(log contract.Logger, spec *openapi3.Swagger, op *Operation, resps *openapi3.Responses) *DataResolver

NewDataResolver creates a new DataResolver instance.

func (*DataResolver) CollectHeaders

func (resolver *DataResolver) CollectHeaders(specResp *openapi3.Response) (
	[]ResolverExpectedHeader,
	error,
)

CollectHeaders collects the headers to expect in response.

func (*DataResolver) Content

func (resolver *DataResolver) Content(mt *openapi3.MediaType, CT string, v contract.Validator) error

Content populates the provided validator with expectations for HTTP response body structure.

func (*DataResolver) Headers

func (resolver *DataResolver) Headers(specResp *openapi3.Response, v contract.Validator) error

Headers populates the provided validator with expectations for HTTP headers.

func (*DataResolver) Host

func (resolver *DataResolver) Host(hostHint string) contract.ParameterSource

Host returns a ParameterSource which contains a host name under the params.KeyHost key to be used in the URL parameter set.

func (*DataResolver) MakeSchema

func (resolver *DataResolver) MakeSchema(
	oasSchemaName string,
	oasSchema *openapi3.Schema,
) (*api.Schema, error)

MakeSchema creates an api.Schema instance from available operation spec data. The schema is later used to test response contents (headers & bodies) against it.

func (*DataResolver) MetaData

func (resolver *DataResolver) MetaData(status int64, CT string) (
	int,
	string,
	*openapi3.MediaType,
	*openapi3.Response,
	error,
)

MetaData populates the provided validator with expectations for HTTP status & content type.

func (*DataResolver) Response

func (resolver *DataResolver) Response(status int64, CT string) contract.Validator

Response returns a Validator instance to test response correctness. Since there may be multiple responses in a OAS spec file, it selects on of them based on the arguments. If no status is supplied then 200 is used by default. If no CT is supplied then "application/json" is used by default.

func (*DataResolver) Security

func (resolver *DataResolver) Security(name string) contract.Security

Security returns a security object to use in request.

func (*DataResolver) SecurityCredentials

func (resolver *DataResolver) SecurityCredentials(scheme *openapi3.SecurityScheme) (string, string, string, error)

SecurityCredentials returns a username, password and token when available.

func (*DataResolver) SecurityName

func (resolver *DataResolver) SecurityName(name string) string

SecurityName figures security scheme name from the operation.

type Operation

type Operation struct {
	*api.OperationPrototype

	RequestMethod string
	RequestPath   string
	SpecPath      *openapi3.PathItem
	SpecOp        *openapi3.Operation

	Resolver *DataResolver
}

Operation provides access to OAS3-specific API data.

func (*Operation) Description

func (op *Operation) Description() string

Description returns an operation description.

func (*Operation) ID

func (op *Operation) ID() string

ID returns an operation ID.

func (*Operation) Method

func (op *Operation) Method() string

Method returns an operation request method.

func (*Operation) Name

func (op *Operation) Name() string

Name returns an operation name.

func (*Operation) Path

func (op *Operation) Path() string

Path returns an operation request path.

func (*Operation) Resolve

func (op *Operation) Resolve() contract.DataResolver

Resolve returns a DataResolver instance which is used to resolve data based on user input.

type ResolverExpectedHeader

type ResolverExpectedHeader struct {
	Name     string
	Schema   *api.Schema
	Required bool
}

ResolverExpectedHeader is header to expect.

type Spec

type Spec struct {
	Log contract.Logger
	OAS *openapi3.Swagger
}

Spec is an OAS3-backed API test spec.

func Load

func Load(path string, logger contract.Logger) (*Spec, error)

Load reads the spec file at path, parses it and returns parsed spec data.

func (*Spec) Description

func (spec *Spec) Description() string

Description return project description.

func (*Spec) GetOperation

func (spec *Spec) GetOperation(name string) contract.Operation

GetOperation returns a list of all available test operations from the spec.

func (*Spec) IterateOverRequiredParameters

func (spec *Spec) IterateOverRequiredParameters(params *openapi3.Parameters, handler func(*openapi3.Parameter))

IterateOverRequiredParameters iterates over items in the provided parameter list and invokes the handler function for every required one.

func (*Spec) MakeOperation

func (spec *Spec) MakeOperation(
	method string,
	oasOp *openapi3.Operation,
	oasPath string,
	oasPathItem *openapi3.PathItem,
) contract.Operation

MakeOperation creates an Operation instance from available spec data.

func (*Spec) Operations

func (spec *Spec) Operations() contract.OperationIterator

Operations returns an iterable channel with operations.

func (*Spec) Title

func (spec *Spec) Title() string

Title return project title.

func (*Spec) Version

func (spec *Spec) Version() string

Version return project version.

type SpecParameterSource

type SpecParameterSource struct {
	Params *openapi3.Parameters
	In     string
	Name   string
}

SpecParameterSource provides access to spec data.

func HeadersParameterSource

func HeadersParameterSource(p *openapi3.Parameters, name string) *SpecParameterSource

HeadersParameterSource creates a parameter source concerned with extracting the "header" parameters from a spec.

func PathParameterSource

func PathParameterSource(p *openapi3.Parameters, name string) *SpecParameterSource

PathParameterSource creates a parameter source concerned with extracting the "path" parameters from a spec.

func QueryParameterSource

func QueryParameterSource(p *openapi3.Parameters, name string) *SpecParameterSource

QueryParameterSource creates a parameter source concerned with extracting the "query" parameters from a spec.

func (*SpecParameterSource) Get

func (ds *SpecParameterSource) Get(n string) string

Get retrieves the requested parameters from the spec parameter list.

func (*SpecParameterSource) Iterate

Iterate returns an iterable channel to read parameter values.

Jump to

Keyboard shortcuts

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