openapi

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: MIT Imports: 11 Imported by: 8

Documentation

Index

Constants

View Source
const (
	InPath   = "path"
	InQuery  = "query"
	InHeader = "header"
	InCookie = "cookie"
	InBody   = "body"

	// This flag indicates that the parameter is located in *http.Request.
	InRequest = "request"

	MediaTypeJSON = "application/json; charset=utf-8"
)

Variables

This section is empty.

Functions

func FromDoc

func FromDoc(data *ifacetool.Data, snakeCase bool) (*Specification, []Transport, error)

Types

type Aliases

type Aliases map[string]string

func (Aliases) Eval

func (a Aliases) Eval(value string) (string, error)

Eval replaces all possible aliases with their values.

func (Aliases) Set

func (a Aliases) Set(key, value string)

type Metadata

type Metadata struct {
	// Relative path to the OAS documentation.
	DocsPath string

	Title       string
	Version     string
	Description string
	BasePath    string

	// Default tags for operations those have no tags.
	DefaultTags []string
}

type Operation

type Operation struct {
	Name             string
	Method           string
	Pattern          string
	Request          Request
	SuccessResponse  *Response
	FailureResponses []*Response
	Description      string
	Tags             []string
}

func DELETE

func DELETE() *Operation

func GET

func GET() *Operation
func HEAD() *Operation

func OPTIONS

func OPTIONS() *Operation

func PATCH

func PATCH() *Operation

func POST

func POST() *Operation

func PUT

func PUT() *Operation

func (*Operation) Alias

func (o *Operation) Alias(name string) *Operation

func (*Operation) Req

func (o *Operation) Req(mediaType string, schema interface{}) *Operation

func (*Operation) Resp

func (o *Operation) Resp(statusCode int, mediaType string, schema interface{}) *Operation

type Param

type Param struct {
	Name        string     // Method argument name
	Type        string     // Method argument type
	RawType     types.Type // The raw Go type of the method argument
	In          string
	Alias       string // Request parameter name
	AliasType   string // Request parameter type
	Required    bool
	Description string // OAS description

	IsBlank bool // Whether this parameter is a blank identifier.
	// contains filtered or unexported fields
}

func (*Param) Set

func (p *Param) Set(o *Param)

Set sets properties according to the values hold by o.

func (*Param) SetAlias

func (p *Param) SetAlias(alias string)

func (*Param) SetByAnnotation

func (p *Param) SetByAnnotation(a *annotation)

Set sets properties according to the given annotation.

func (*Param) SetDescription

func (p *Param) SetDescription(descr string)

func (*Param) SetName

func (p *Param) SetName(name string, snakeCase bool)

type Parser

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

func (*Parser) GetParam

func (p *Parser) GetParam(name string) (*Param, error)

func (*Parser) Parse

func (p *Parser) Parse(text string) ([]*annotation, error)

type Request

type Request struct {
	MediaType string

	// The name of the request field whose value is mapped to the HTTP request body.
	// Otherwise, all fields not located in path/query/header will be mapped to the HTTP body
	BodyField string

	Params []*Param
}

type Response

type Response struct {
	StatusCode int
	MediaType  string
	Schema     interface{}

	// The name of the response field whose value is mapped to the HTTP response body.
	// When omitted, the entire response struct will be used as the HTTP response body.
	BodyField string
}

type Specification

type Specification struct {
	Metadata   *Metadata
	Operations []*Operation
}

func Spec

func Spec() *Specification

func (*Specification) Path

func (s *Specification) Path(pattern string, operations ...*Operation) *Specification

type Transport

type Transport int
const (
	OptionNoBody = "-"

	TransportHTTP Transport = 0b0001
	TransportGRPC Transport = 0b0010
	TransportAll  Transport = 0b0011
)

Jump to

Keyboard shortcuts

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