openapi

package
v1.8.0-beta.6 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeJson = "application/json"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Components

type Components struct {
	Schemas         map[string]Schema         `json:"schemas,omitempty"`
	SecuritySchemes map[string]SecurityScheme `json:"securitySchemes,omitempty"`
}

type Contact

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

type Encoding

type Encoding struct {
	ContentType   string            `json:"contentType,omitempty"`
	Headers       map[string]Header `json:"headers,omitempty"`
	Style         string            `json:"style,omitempty"`
	Explode       bool              `json:"explode,omitempty"`
	AllowReserved bool              `json:"allowReserved,omitempty"`
}

type Example

type Example struct {
	Summary       string      `json:"summary,omitempty"`
	Description   string      `json:"description,omitempty"`
	Value         interface{} `json:"value,omitempty"`
	ExternalValue string      `json:"externalValue,omitempty"`
}

type ExternalDoc

type ExternalDoc struct {
}
type Header struct {
	Description     string  `json:"description,omitempty"`
	Required        bool    `json:"required,omitempty"`
	Deprecated      bool    `json:"deprecated,omitempty"`
	AllowEmptyValue bool    `json:"allowEmptyValue,omitempty"`
	Schema          *Schema `json:"schema,omitempty"`
}

type Info

type Info struct {
	Title          string   `json:"title,omitempty"`
	Description    string   `json:"description,omitempty"`
	TermsOfService string   `json:"termsOfService,omitempty"`
	Contact        *Contact `json:"contact,omitempty"`
	License        *License `json:"license,omitempty"`
	Version        string   `json:"version,omitempty"`
}

func NewInfo

func NewInfo(title, description, version string) *Info

type License

type License struct {
	Name string `json:"name,omitempty"`
	URL  string `json:"url,omitempty"`
}
type Link struct {
	OperationRef string                 `json:"operationRef,omitempty"`
	OperationId  string                 `json:"operationId,omitempty"`
	Parameters   map[string]interface{} `json:"parameters,omitempty"`
	RequestBody  interface{}            `json:"requestBody,omitempty"`
	Description  string                 `json:"description,omitempty"`
	Server       Server                 `json:"server,omitempty"`
}

type MediaType

type MediaType struct {
	Schema   *Schema             `json:"schema,omitempty"`
	Example  interface{}         `json:"example,omitempty"`
	Examples map[string]Example  `json:"examples,omitempty"`
	Encoding map[string]Encoding `json:"encoding,omitempty"`
}

type OAuthFlow

type OAuthFlow struct {
}

type OpenAPI

type OpenAPI struct {
	OpenAPI    string                `json:"openapi,omitempty"`
	Info       *Info                 `json:"info,omitempty"`
	Servers    []*Server             `json:"servers,omitempty"`
	Paths      map[string]*PathItem  `json:"paths,omitempty"`
	Components Components            `json:"components,omitempty"`
	Security   []SecurityRequirement `json:"security,omitempty"`
	// Not in OpenAPI spec
	Client *http.Client    `json:"-"`
	ApiKey *SecurityScheme `json:"-"`
}

func New

func New(openapi string, info *Info, server *Server) *OpenAPI

func (*OpenAPI) ApiURL

func (oa *OpenAPI) ApiURL(path string) string

func (*OpenAPI) AuthApiKey

func (oa *OpenAPI) AuthApiKey(header string, value string)

func (*OpenAPI) Do

func (oa *OpenAPI) Do(base PathItem, op Operation)

func (*OpenAPI) FirstServer

func (oa *OpenAPI) FirstServer() *Server

func (*OpenAPI) Prepare

func (oa *OpenAPI) Prepare(method string, path string, data []byte, params map[string]string, headers map[string]string) *http.Request

type OpenAPIBuilder

type OpenAPIBuilder struct {
	OpenAPI *OpenAPI
	// contains filtered or unexported fields
}

type Operation

type Operation struct {
	Tags         []string     `json:"tags,omitempty"`
	Summary      string       `json:"summary,omitempty"`
	Description  string       `json:"description,omitempty"`
	ExternalDocs *ExternalDoc `json:"externalDocs,omitempty"`
	OperationId  string       `json:"operationId,omitempty"`
	Parameters   []*Parameter `json:"parameters,omitempty"`
	RequestBody  *RequestBody `json:"requestBody,omitempty"`
	Responses    Responses    `json:"responses,omitempty"`
	//Callbacks    Callback
	Deprecated bool                `json:"deprecated,omitempty"`
	Security   SecurityRequirement `json:"security,omitempty"`
	Servers    []Server            `json:"servers,omitempty"`
	// Not OpenAPI standard
	Method string      `json:"-"`
	Output interface{} `json:"-"`
}

func (*Operation) Merge

func (o *Operation) Merge(other *Operation)

func (*Operation) ParseResponse

func (o *Operation) ParseResponse(r *http.Response) (err error)

type Parameter

type Parameter struct {
	Name            string  `json:"name,omitempty"`
	In              string  `json:"in,omitempty"`
	Description     string  `json:"description,omitempty"`
	Required        bool    `json:"required"`
	Deprecated      bool    `json:"deprecated,omitempty"`
	AllowEmptyValue bool    `json:"allowEmptyValue"`
	Schema          *Schema `json:"schema,omitempty"`
	// Not OpenAPI standard
	Value string `json:"-"`
	// contains filtered or unexported fields
}

func PathParameter

func PathParameter(name string, value interface{}, opts ...string) *Parameter

func QueryParameter

func QueryParameter(name string, value interface{}, opts ...string) *Parameter

func (*Parameter) Require

func (p *Parameter) Require() *Parameter

func (*Parameter) Skip

func (p *Parameter) Skip() *Parameter

func (*Parameter) Suffix

func (p *Parameter) Suffix(s string) *Parameter

type PathItem

type PathItem struct {
	Ref         string      `json:"$ref,omitempty"`
	Summary     string      `json:"summary,omitempty"`
	Description string      `json:"description,omitempty"`
	Get         *Operation  `json:"get,omitempty"`
	Put         *Operation  `json:"put,omitempty"`
	Post        *Operation  `json:"post,omitempty"`
	Delete      *Operation  `json:"delete,omitempty"`
	Options     *Operation  `json:"options,omitempty"`
	Head        *Operation  `json:"head,omitempty"`
	Patch       *Operation  `json:"patch,omitempty"`
	Trace       *Operation  `json:"trace,omitempty"`
	Servers     []Server    `json:"servers,omitempty"`
	Parameters  []Parameter `json:"parameters,omitempty"`
	// Not OpenAPI standard
	Value string `json:"-"`
}

func (*PathItem) Merge

func (p *PathItem) Merge(other *PathItem)

func (*PathItem) Update

func (p *PathItem) Update()

type RequestBody

type RequestBody struct {
	Description string               `json:"description,omitempty"`
	Content     map[string]MediaType `json:"content,omitempty"`
	Required    bool                 `json:"required,omitempty"`
}

func JsonRequestBody

func JsonRequestBody(desc string, data interface{}, required bool) *RequestBody

func MakeRequestBody

func MakeRequestBody(desc, contentType string, data interface{}, required bool) *RequestBody

func (*RequestBody) ContentBytes

func (r *RequestBody) ContentBytes() (b []byte, err error)

type Response

type Response struct {
	Description string               `json:"description,omitempty"`
	Headers     map[string]Header    `json:"headers,omitempty"`
	Content     map[string]MediaType `json:"content,omitempty"`
	Links       map[string]Link      `json:"links,omitempty"`
}

type Responses

type Responses map[string]Response

type Schema

type Schema struct {
	Type       string             `json:"type,omitempty"`
	Format     string             `json:"format,omitempty"`
	Properties map[string]*Schema `json:"properties,omitempty"`
	Items      *Schema            `json:"items,omitempty"`
}

func SchemaFrom

func SchemaFrom(i interface{}, contentType string) (s *Schema)

func SchemaFromString

func SchemaFromString(s string) *Schema

type SecurityRequirement

type SecurityRequirement map[string][]string

type SecurityScheme

type SecurityScheme struct {
	Type             string     `json:"type,omitempty"`
	Description      string     `json:"description,omitempty"`
	Name             string     `json:"name,omitempty"`
	In               string     `json:"in,omitempty"`
	Scheme           string     `json:"scheme,omitempty"`
	BearerFormat     string     `json:"bearerFormat,omitempty"`
	Flows            *OAuthFlow `json:"flows,omitempty"`
	OpenIdConnectUrl string     `json:"openIdConnect_url,omitempty"`
	// Not in OpenAPI spec but here for easier integration
	Value string `json:"-"`
}

type Server

type Server struct {
	URL         string                    `json:"url,omitempty"`
	Description string                    `json:"description,omitempty"`
	Variables   map[string]ServerVariable `json:"variables,omitempty"`
}

type ServerVariable

type ServerVariable struct {
	Enum        []string `json:"enum,omitempty"`
	Default     string   `json:"default,omitempty"`
	Description string   `json:"description,omitempty"`
}

Jump to

Keyboard shortcuts

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