Documentation
¶
Overview ¶
Package openapi2 parses and writes OpenAPIv2 specification documents.
Does not cover all elements of OpenAPIv2. When OpenAPI version 3 is backwards-compatible with version 2, version 3 elements have been used.
See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md
Example ¶
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"reflect"
"github.com/TykTechnologies/legacy-kin-openapi/openapi2"
"github.com/ghodss/yaml"
)
func main() {
input, err := ioutil.ReadFile("testdata/swagger.json")
if err != nil {
panic(err)
}
var doc openapi2.T
if err = json.Unmarshal(input, &doc); err != nil {
panic(err)
}
if doc.ExternalDocs.Description != "Find out more about Swagger" {
panic(`doc.ExternalDocs was parsed incorrectly!`)
}
outputJSON, err := json.Marshal(doc)
if err != nil {
panic(err)
}
var docAgainFromJSON openapi2.T
if err = json.Unmarshal(outputJSON, &docAgainFromJSON); err != nil {
panic(err)
}
if !reflect.DeepEqual(doc, docAgainFromJSON) {
fmt.Println("objects doc & docAgainFromJSON should be the same")
}
outputYAML, err := yaml.Marshal(doc)
if err != nil {
panic(err)
}
var docAgainFromYAML openapi2.T
if err = yaml.Unmarshal(outputYAML, &docAgainFromYAML); err != nil {
panic(err)
}
if !reflect.DeepEqual(doc, docAgainFromYAML) {
fmt.Println("objects doc & docAgainFromYAML should be the same")
}
}
Index ¶
- type Header
- type Operation
- type Parameter
- type Parameters
- type PathItem
- func (pathItem *PathItem) GetOperation(method string) *Operation
- func (pathItem *PathItem) MarshalJSON() ([]byte, error)
- func (pathItem *PathItem) Operations() map[string]*Operation
- func (pathItem *PathItem) SetOperation(method string, operation *Operation)
- func (pathItem *PathItem) UnmarshalJSON(data []byte) error
- type Response
- type SecurityRequirements
- type SecurityScheme
- type T
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Header ¶
type Header struct {
Parameter
}
func (*Header) MarshalJSON ¶
func (*Header) UnmarshalJSON ¶
type Operation ¶
type Operation struct {
openapi3.ExtensionProps
Summary string `json:"summary,omitempty" yaml:"summary,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
ExternalDocs *openapi3.ExternalDocs `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`
OperationID string `json:"operationId,omitempty" yaml:"operationId,omitempty"`
Parameters Parameters `json:"parameters,omitempty" yaml:"parameters,omitempty"`
Responses map[string]*Response `json:"responses" yaml:"responses"`
Consumes []string `json:"consumes,omitempty" yaml:"consumes,omitempty"`
Produces []string `json:"produces,omitempty" yaml:"produces,omitempty"`
Security *SecurityRequirements `json:"security,omitempty" yaml:"security,omitempty"`
}
func (*Operation) MarshalJSON ¶
func (*Operation) UnmarshalJSON ¶
type Parameter ¶
type Parameter struct {
openapi3.ExtensionProps
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
In string `json:"in,omitempty" yaml:"in,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
CollectionFormat string `json:"collectionFormat,omitempty" yaml:"collectionFormat,omitempty"`
Type string `json:"type,omitempty" yaml:"type,omitempty"`
Format string `json:"format,omitempty" yaml:"format,omitempty"`
Pattern string `json:"pattern,omitempty" yaml:"pattern,omitempty"`
AllowEmptyValue bool `json:"allowEmptyValue,omitempty" yaml:"allowEmptyValue,omitempty"`
Required bool `json:"required,omitempty" yaml:"required,omitempty"`
UniqueItems bool `json:"uniqueItems,omitempty" yaml:"uniqueItems,omitempty"`
ExclusiveMin bool `json:"exclusiveMinimum,omitempty" yaml:"exclusiveMinimum,omitempty"`
ExclusiveMax bool `json:"exclusiveMaximum,omitempty" yaml:"exclusiveMaximum,omitempty"`
Schema *openapi3.SchemaRef `json:"schema,omitempty" yaml:"schema,omitempty"`
Items *openapi3.SchemaRef `json:"items,omitempty" yaml:"items,omitempty"`
Enum []interface{} `json:"enum,omitempty" yaml:"enum,omitempty"`
MultipleOf *float64 `json:"multipleOf,omitempty" yaml:"multipleOf,omitempty"`
Minimum *float64 `json:"minimum,omitempty" yaml:"minimum,omitempty"`
Maximum *float64 `json:"maximum,omitempty" yaml:"maximum,omitempty"`
MaxLength *uint64 `json:"maxLength,omitempty" yaml:"maxLength,omitempty"`
MaxItems *uint64 `json:"maxItems,omitempty" yaml:"maxItems,omitempty"`
MinLength uint64 `json:"minLength,omitempty" yaml:"minLength,omitempty"`
MinItems uint64 `json:"minItems,omitempty" yaml:"minItems,omitempty"`
Default interface{} `json:"default,omitempty" yaml:"default,omitempty"`
}
func (*Parameter) MarshalJSON ¶
func (*Parameter) UnmarshalJSON ¶
type Parameters ¶
type Parameters []*Parameter
func (Parameters) Len ¶
func (ps Parameters) Len() int
func (Parameters) Less ¶
func (ps Parameters) Less(i, j int) bool
func (Parameters) Swap ¶
func (ps Parameters) Swap(i, j int)
type PathItem ¶
type PathItem struct {
openapi3.ExtensionProps
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
Delete *Operation `json:"delete,omitempty" yaml:"delete,omitempty"`
Get *Operation `json:"get,omitempty" yaml:"get,omitempty"`
Head *Operation `json:"head,omitempty" yaml:"head,omitempty"`
Options *Operation `json:"options,omitempty" yaml:"options,omitempty"`
Patch *Operation `json:"patch,omitempty" yaml:"patch,omitempty"`
Post *Operation `json:"post,omitempty" yaml:"post,omitempty"`
Put *Operation `json:"put,omitempty" yaml:"put,omitempty"`
Parameters Parameters `json:"parameters,omitempty" yaml:"parameters,omitempty"`
}
func (*PathItem) GetOperation ¶
func (*PathItem) MarshalJSON ¶
func (*PathItem) Operations ¶
func (*PathItem) SetOperation ¶
func (*PathItem) UnmarshalJSON ¶
type Response ¶
type Response struct {
openapi3.ExtensionProps
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Schema *openapi3.SchemaRef `json:"schema,omitempty" yaml:"schema,omitempty"`
Headers map[string]*Header `json:"headers,omitempty" yaml:"headers,omitempty"`
Examples map[string]interface{} `json:"examples,omitempty" yaml:"examples,omitempty"`
}
func (*Response) MarshalJSON ¶
func (*Response) UnmarshalJSON ¶
type SecurityRequirements ¶
type SecurityScheme ¶
type SecurityScheme struct {
openapi3.ExtensionProps
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Type string `json:"type,omitempty" yaml:"type,omitempty"`
In string `json:"in,omitempty" yaml:"in,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Flow string `json:"flow,omitempty" yaml:"flow,omitempty"`
AuthorizationURL string `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"`
TokenURL string `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty"`
Scopes map[string]string `json:"scopes,omitempty" yaml:"scopes,omitempty"`
Tags openapi3.Tags `json:"tags,omitempty" yaml:"tags,omitempty"`
}
func (*SecurityScheme) MarshalJSON ¶
func (securityScheme *SecurityScheme) MarshalJSON() ([]byte, error)
func (*SecurityScheme) UnmarshalJSON ¶
func (securityScheme *SecurityScheme) UnmarshalJSON(data []byte) error
type T ¶
type T struct {
openapi3.ExtensionProps
Swagger string `json:"swagger" yaml:"swagger"`
Info openapi3.Info `json:"info" yaml:"info"`
ExternalDocs *openapi3.ExternalDocs `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
Schemes []string `json:"schemes,omitempty" yaml:"schemes,omitempty"`
Consumes []string `json:"consumes,omitempty" yaml:"consumes,omitempty"`
Produces []string `json:"produces,omitempty" yaml:"produces,omitempty"`
Host string `json:"host,omitempty" yaml:"host,omitempty"`
BasePath string `json:"basePath,omitempty" yaml:"basePath,omitempty"`
Paths map[string]*PathItem `json:"paths,omitempty" yaml:"paths,omitempty"`
Definitions map[string]*openapi3.SchemaRef `json:"definitions,omitempty,noref" yaml:"definitions,omitempty,noref"`
Parameters map[string]*Parameter `json:"parameters,omitempty,noref" yaml:"parameters,omitempty,noref"`
Responses map[string]*Response `json:"responses,omitempty,noref" yaml:"responses,omitempty,noref"`
SecurityDefinitions map[string]*SecurityScheme `json:"securityDefinitions,omitempty" yaml:"securityDefinitions,omitempty"`
Security SecurityRequirements `json:"security,omitempty" yaml:"security,omitempty"`
Tags openapi3.Tags `json:"tags,omitempty" yaml:"tags,omitempty"`
}
T is the root of an OpenAPI v2 document
func (*T) AddOperation ¶
func (*T) MarshalJSON ¶
func (*T) UnmarshalJSON ¶
Click to show internal directories.
Click to hide internal directories.