|
1 |
| -type Header struct{ ... } |
2 |
| -type Operation struct{ ... } |
3 |
| -type Parameter struct{ ... } |
| 1 | +package openapi2 // import "github.com/getkin/kin-openapi/openapi2" |
| 2 | + |
| 3 | +Package openapi2 parses and writes OpenAPIv2 specification documents. |
| 4 | + |
| 5 | +Does not cover all elements of OpenAPIv2. When OpenAPI version 3 is |
| 6 | +backwards-compatible with version 2, version 3 elements have been used. |
| 7 | + |
| 8 | +See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md |
| 9 | + |
| 10 | +TYPES |
| 11 | + |
| 12 | +type Header struct { |
| 13 | + Parameter |
| 14 | +} |
| 15 | + |
| 16 | +func (header Header) MarshalJSON() ([]byte, error) |
| 17 | + MarshalJSON returns the JSON encoding of Header. |
| 18 | + |
| 19 | +func (header *Header) UnmarshalJSON(data []byte) error |
| 20 | + UnmarshalJSON sets Header to a copy of data. |
| 21 | + |
| 22 | +type Operation struct { |
| 23 | + Extensions map[string]interface{} `json:"-" yaml:"-"` |
| 24 | + |
| 25 | + Summary string `json:"summary,omitempty" yaml:"summary,omitempty"` |
| 26 | + Description string `json:"description,omitempty" yaml:"description,omitempty"` |
| 27 | + Deprecated bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty"` |
| 28 | + ExternalDocs *openapi3.ExternalDocs `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"` |
| 29 | + Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"` |
| 30 | + OperationID string `json:"operationId,omitempty" yaml:"operationId,omitempty"` |
| 31 | + Parameters Parameters `json:"parameters,omitempty" yaml:"parameters,omitempty"` |
| 32 | + Responses map[string]*Response `json:"responses" yaml:"responses"` |
| 33 | + Consumes []string `json:"consumes,omitempty" yaml:"consumes,omitempty"` |
| 34 | + Produces []string `json:"produces,omitempty" yaml:"produces,omitempty"` |
| 35 | + Schemes []string `json:"schemes,omitempty" yaml:"schemes,omitempty"` |
| 36 | + Security *SecurityRequirements `json:"security,omitempty" yaml:"security,omitempty"` |
| 37 | +} |
| 38 | + |
| 39 | +func (operation Operation) MarshalJSON() ([]byte, error) |
| 40 | + MarshalJSON returns the JSON encoding of Operation. |
| 41 | + |
| 42 | +func (operation *Operation) UnmarshalJSON(data []byte) error |
| 43 | + UnmarshalJSON sets Operation to a copy of data. |
| 44 | + |
| 45 | +type Parameter struct { |
| 46 | + Extensions map[string]interface{} `json:"-" yaml:"-"` |
| 47 | + |
| 48 | + Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"` |
| 49 | + |
| 50 | + In string `json:"in,omitempty" yaml:"in,omitempty"` |
| 51 | + Name string `json:"name,omitempty" yaml:"name,omitempty"` |
| 52 | + Description string `json:"description,omitempty" yaml:"description,omitempty"` |
| 53 | + CollectionFormat string `json:"collectionFormat,omitempty" yaml:"collectionFormat,omitempty"` |
| 54 | + Type string `json:"type,omitempty" yaml:"type,omitempty"` |
| 55 | + Format string `json:"format,omitempty" yaml:"format,omitempty"` |
| 56 | + Pattern string `json:"pattern,omitempty" yaml:"pattern,omitempty"` |
| 57 | + AllowEmptyValue bool `json:"allowEmptyValue,omitempty" yaml:"allowEmptyValue,omitempty"` |
| 58 | + Required bool `json:"required,omitempty" yaml:"required,omitempty"` |
| 59 | + UniqueItems bool `json:"uniqueItems,omitempty" yaml:"uniqueItems,omitempty"` |
| 60 | + ExclusiveMin bool `json:"exclusiveMinimum,omitempty" yaml:"exclusiveMinimum,omitempty"` |
| 61 | + ExclusiveMax bool `json:"exclusiveMaximum,omitempty" yaml:"exclusiveMaximum,omitempty"` |
| 62 | + Schema *openapi3.SchemaRef `json:"schema,omitempty" yaml:"schema,omitempty"` |
| 63 | + Items *openapi3.SchemaRef `json:"items,omitempty" yaml:"items,omitempty"` |
| 64 | + Enum []interface{} `json:"enum,omitempty" yaml:"enum,omitempty"` |
| 65 | + MultipleOf *float64 `json:"multipleOf,omitempty" yaml:"multipleOf,omitempty"` |
| 66 | + Minimum *float64 `json:"minimum,omitempty" yaml:"minimum,omitempty"` |
| 67 | + Maximum *float64 `json:"maximum,omitempty" yaml:"maximum,omitempty"` |
| 68 | + MaxLength *uint64 `json:"maxLength,omitempty" yaml:"maxLength,omitempty"` |
| 69 | + MaxItems *uint64 `json:"maxItems,omitempty" yaml:"maxItems,omitempty"` |
| 70 | + MinLength uint64 `json:"minLength,omitempty" yaml:"minLength,omitempty"` |
| 71 | + MinItems uint64 `json:"minItems,omitempty" yaml:"minItems,omitempty"` |
| 72 | + Default interface{} `json:"default,omitempty" yaml:"default,omitempty"` |
| 73 | +} |
| 74 | + |
| 75 | +func (parameter Parameter) MarshalJSON() ([]byte, error) |
| 76 | + MarshalJSON returns the JSON encoding of Parameter. |
| 77 | + |
| 78 | +func (parameter *Parameter) UnmarshalJSON(data []byte) error |
| 79 | + UnmarshalJSON sets Parameter to a copy of data. |
| 80 | + |
4 | 81 | type Parameters []*Parameter
|
5 |
| -type PathItem struct{ ... } |
6 |
| -type Response struct{ ... } |
| 82 | + |
| 83 | +func (ps Parameters) Len() int |
| 84 | + |
| 85 | +func (ps Parameters) Less(i, j int) bool |
| 86 | + |
| 87 | +func (ps Parameters) Swap(i, j int) |
| 88 | + |
| 89 | +type PathItem struct { |
| 90 | + Extensions map[string]interface{} `json:"-" yaml:"-"` |
| 91 | + |
| 92 | + Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"` |
| 93 | + |
| 94 | + Delete *Operation `json:"delete,omitempty" yaml:"delete,omitempty"` |
| 95 | + Get *Operation `json:"get,omitempty" yaml:"get,omitempty"` |
| 96 | + Head *Operation `json:"head,omitempty" yaml:"head,omitempty"` |
| 97 | + Options *Operation `json:"options,omitempty" yaml:"options,omitempty"` |
| 98 | + Patch *Operation `json:"patch,omitempty" yaml:"patch,omitempty"` |
| 99 | + Post *Operation `json:"post,omitempty" yaml:"post,omitempty"` |
| 100 | + Put *Operation `json:"put,omitempty" yaml:"put,omitempty"` |
| 101 | + Parameters Parameters `json:"parameters,omitempty" yaml:"parameters,omitempty"` |
| 102 | +} |
| 103 | + |
| 104 | +func (pathItem *PathItem) GetOperation(method string) *Operation |
| 105 | + |
| 106 | +func (pathItem PathItem) MarshalJSON() ([]byte, error) |
| 107 | + MarshalJSON returns the JSON encoding of PathItem. |
| 108 | + |
| 109 | +func (pathItem *PathItem) Operations() map[string]*Operation |
| 110 | + |
| 111 | +func (pathItem *PathItem) SetOperation(method string, operation *Operation) |
| 112 | + |
| 113 | +func (pathItem *PathItem) UnmarshalJSON(data []byte) error |
| 114 | + UnmarshalJSON sets PathItem to a copy of data. |
| 115 | + |
| 116 | +type Response struct { |
| 117 | + Extensions map[string]interface{} `json:"-" yaml:"-"` |
| 118 | + |
| 119 | + Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"` |
| 120 | + |
| 121 | + Description string `json:"description,omitempty" yaml:"description,omitempty"` |
| 122 | + Schema *openapi3.SchemaRef `json:"schema,omitempty" yaml:"schema,omitempty"` |
| 123 | + Headers map[string]*Header `json:"headers,omitempty" yaml:"headers,omitempty"` |
| 124 | + Examples map[string]interface{} `json:"examples,omitempty" yaml:"examples,omitempty"` |
| 125 | +} |
| 126 | + |
| 127 | +func (response Response) MarshalJSON() ([]byte, error) |
| 128 | + MarshalJSON returns the JSON encoding of Response. |
| 129 | + |
| 130 | +func (response *Response) UnmarshalJSON(data []byte) error |
| 131 | + UnmarshalJSON sets Response to a copy of data. |
| 132 | + |
7 | 133 | type SecurityRequirements []map[string][]string
|
8 |
| -type SecurityScheme struct{ ... } |
9 |
| -type T struct{ ... } |
| 134 | + |
| 135 | +type SecurityScheme struct { |
| 136 | + Extensions map[string]interface{} `json:"-" yaml:"-"` |
| 137 | + |
| 138 | + Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"` |
| 139 | + |
| 140 | + Description string `json:"description,omitempty" yaml:"description,omitempty"` |
| 141 | + Type string `json:"type,omitempty" yaml:"type,omitempty"` |
| 142 | + In string `json:"in,omitempty" yaml:"in,omitempty"` |
| 143 | + Name string `json:"name,omitempty" yaml:"name,omitempty"` |
| 144 | + Flow string `json:"flow,omitempty" yaml:"flow,omitempty"` |
| 145 | + AuthorizationURL string `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"` |
| 146 | + TokenURL string `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty"` |
| 147 | + Scopes map[string]string `json:"scopes,omitempty" yaml:"scopes,omitempty"` |
| 148 | + Tags openapi3.Tags `json:"tags,omitempty" yaml:"tags,omitempty"` |
| 149 | +} |
| 150 | + |
| 151 | +func (securityScheme SecurityScheme) MarshalJSON() ([]byte, error) |
| 152 | + MarshalJSON returns the JSON encoding of SecurityScheme. |
| 153 | + |
| 154 | +func (securityScheme *SecurityScheme) UnmarshalJSON(data []byte) error |
| 155 | + UnmarshalJSON sets SecurityScheme to a copy of data. |
| 156 | + |
| 157 | +type T struct { |
| 158 | + Extensions map[string]interface{} `json:"-" yaml:"-"` |
| 159 | + |
| 160 | + Swagger string `json:"swagger" yaml:"swagger"` // required |
| 161 | + Info openapi3.Info `json:"info" yaml:"info"` // required |
| 162 | + ExternalDocs *openapi3.ExternalDocs `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"` |
| 163 | + Schemes []string `json:"schemes,omitempty" yaml:"schemes,omitempty"` |
| 164 | + Consumes []string `json:"consumes,omitempty" yaml:"consumes,omitempty"` |
| 165 | + Produces []string `json:"produces,omitempty" yaml:"produces,omitempty"` |
| 166 | + Host string `json:"host,omitempty" yaml:"host,omitempty"` |
| 167 | + BasePath string `json:"basePath,omitempty" yaml:"basePath,omitempty"` |
| 168 | + Paths map[string]*PathItem `json:"paths,omitempty" yaml:"paths,omitempty"` |
| 169 | + Definitions map[string]*openapi3.SchemaRef `json:"definitions,omitempty" yaml:"definitions,omitempty"` |
| 170 | + Parameters map[string]*Parameter `json:"parameters,omitempty" yaml:"parameters,omitempty"` |
| 171 | + Responses map[string]*Response `json:"responses,omitempty" yaml:"responses,omitempty"` |
| 172 | + SecurityDefinitions map[string]*SecurityScheme `json:"securityDefinitions,omitempty" yaml:"securityDefinitions,omitempty"` |
| 173 | + Security SecurityRequirements `json:"security,omitempty" yaml:"security,omitempty"` |
| 174 | + Tags openapi3.Tags `json:"tags,omitempty" yaml:"tags,omitempty"` |
| 175 | +} |
| 176 | + T is the root of an OpenAPI v2 document |
| 177 | + |
| 178 | +func (doc *T) AddOperation(path string, method string, operation *Operation) |
| 179 | + |
| 180 | +func (doc T) MarshalJSON() ([]byte, error) |
| 181 | + MarshalJSON returns the JSON encoding of T. |
| 182 | + |
| 183 | +func (doc *T) UnmarshalJSON(data []byte) error |
| 184 | + UnmarshalJSON sets T to a copy of data. |
| 185 | + |
0 commit comments