|
Packit Service |
3a6627 |
package openapi3
|
|
Packit Service |
3a6627 |
|
|
Packit Service |
3a6627 |
import (
|
|
Packit Service |
3a6627 |
"context"
|
|
Packit Service |
3a6627 |
"fmt"
|
|
Packit Service |
3a6627 |
"net/http"
|
|
Packit Service |
3a6627 |
|
|
Packit Service |
3a6627 |
"github.com/getkin/kin-openapi/jsoninfo"
|
|
Packit Service |
3a6627 |
)
|
|
Packit Service |
3a6627 |
|
|
Packit Service |
3a6627 |
type PathItem struct {
|
|
Packit Service |
3a6627 |
ExtensionProps
|
|
Packit Service |
3a6627 |
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
|
|
Packit Service |
3a6627 |
Summary string `json:"summary,omitempty" yaml:"summary,omitempty"`
|
|
Packit Service |
3a6627 |
Description string `json:"description,omitempty" yaml:"description,omitempty"`
|
|
Packit Service |
3a6627 |
Connect *Operation `json:"connect,omitempty" yaml:"connect,omitempty"`
|
|
Packit Service |
3a6627 |
Delete *Operation `json:"delete,omitempty" yaml:"delete,omitempty"`
|
|
Packit Service |
3a6627 |
Get *Operation `json:"get,omitempty" yaml:"get,omitempty"`
|
|
Packit Service |
3a6627 |
Head *Operation `json:"head,omitempty" yaml:"head,omitempty"`
|
|
Packit Service |
3a6627 |
Options *Operation `json:"options,omitempty" yaml:"options,omitempty"`
|
|
Packit Service |
3a6627 |
Patch *Operation `json:"patch,omitempty" yaml:"patch,omitempty"`
|
|
Packit Service |
3a6627 |
Post *Operation `json:"post,omitempty" yaml:"post,omitempty"`
|
|
Packit Service |
3a6627 |
Put *Operation `json:"put,omitempty" yaml:"put,omitempty"`
|
|
Packit Service |
3a6627 |
Trace *Operation `json:"trace,omitempty" yaml:"trace,omitempty"`
|
|
Packit Service |
3a6627 |
Servers Servers `json:"servers,omitempty" yaml:"servers,omitempty"`
|
|
Packit Service |
3a6627 |
Parameters Parameters `json:"parameters,omitempty" yaml:"parameters,omitempty"`
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
|
|
Packit Service |
3a6627 |
func (pathItem *PathItem) MarshalJSON() ([]byte, error) {
|
|
Packit Service |
3a6627 |
return jsoninfo.MarshalStrictStruct(pathItem)
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
|
|
Packit Service |
3a6627 |
func (pathItem *PathItem) UnmarshalJSON(data []byte) error {
|
|
Packit Service |
3a6627 |
return jsoninfo.UnmarshalStrictStruct(data, pathItem)
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
|
|
Packit Service |
3a6627 |
func (pathItem *PathItem) Operations() map[string]*Operation {
|
|
Packit Service |
3a6627 |
operations := make(map[string]*Operation, 4)
|
|
Packit Service |
3a6627 |
if v := pathItem.Connect; v != nil {
|
|
Packit Service |
3a6627 |
operations[http.MethodConnect] = v
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
if v := pathItem.Delete; v != nil {
|
|
Packit Service |
3a6627 |
operations[http.MethodDelete] = v
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
if v := pathItem.Get; v != nil {
|
|
Packit Service |
3a6627 |
operations[http.MethodGet] = v
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
if v := pathItem.Head; v != nil {
|
|
Packit Service |
3a6627 |
operations[http.MethodHead] = v
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
if v := pathItem.Options; v != nil {
|
|
Packit Service |
3a6627 |
operations[http.MethodOptions] = v
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
if v := pathItem.Patch; v != nil {
|
|
Packit Service |
3a6627 |
operations[http.MethodPatch] = v
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
if v := pathItem.Post; v != nil {
|
|
Packit Service |
3a6627 |
operations[http.MethodPost] = v
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
if v := pathItem.Put; v != nil {
|
|
Packit Service |
3a6627 |
operations[http.MethodPut] = v
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
if v := pathItem.Trace; v != nil {
|
|
Packit Service |
3a6627 |
operations[http.MethodTrace] = v
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
return operations
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
|
|
Packit Service |
3a6627 |
func (pathItem *PathItem) GetOperation(method string) *Operation {
|
|
Packit Service |
3a6627 |
switch method {
|
|
Packit Service |
3a6627 |
case http.MethodConnect:
|
|
Packit Service |
3a6627 |
return pathItem.Connect
|
|
Packit Service |
3a6627 |
case http.MethodDelete:
|
|
Packit Service |
3a6627 |
return pathItem.Delete
|
|
Packit Service |
3a6627 |
case http.MethodGet:
|
|
Packit Service |
3a6627 |
return pathItem.Get
|
|
Packit Service |
3a6627 |
case http.MethodHead:
|
|
Packit Service |
3a6627 |
return pathItem.Head
|
|
Packit Service |
3a6627 |
case http.MethodOptions:
|
|
Packit Service |
3a6627 |
return pathItem.Options
|
|
Packit Service |
3a6627 |
case http.MethodPatch:
|
|
Packit Service |
3a6627 |
return pathItem.Patch
|
|
Packit Service |
3a6627 |
case http.MethodPost:
|
|
Packit Service |
3a6627 |
return pathItem.Post
|
|
Packit Service |
3a6627 |
case http.MethodPut:
|
|
Packit Service |
3a6627 |
return pathItem.Put
|
|
Packit Service |
3a6627 |
case http.MethodTrace:
|
|
Packit Service |
3a6627 |
return pathItem.Trace
|
|
Packit Service |
3a6627 |
default:
|
|
Packit Service |
3a6627 |
panic(fmt.Errorf("Unsupported HTTP method '%s'", method))
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
|
|
Packit Service |
3a6627 |
func (pathItem *PathItem) SetOperation(method string, operation *Operation) {
|
|
Packit Service |
3a6627 |
switch method {
|
|
Packit Service |
3a6627 |
case http.MethodConnect:
|
|
Packit Service |
3a6627 |
pathItem.Connect = operation
|
|
Packit Service |
3a6627 |
case http.MethodDelete:
|
|
Packit Service |
3a6627 |
pathItem.Delete = operation
|
|
Packit Service |
3a6627 |
case http.MethodGet:
|
|
Packit Service |
3a6627 |
pathItem.Get = operation
|
|
Packit Service |
3a6627 |
case http.MethodHead:
|
|
Packit Service |
3a6627 |
pathItem.Head = operation
|
|
Packit Service |
3a6627 |
case http.MethodOptions:
|
|
Packit Service |
3a6627 |
pathItem.Options = operation
|
|
Packit Service |
3a6627 |
case http.MethodPatch:
|
|
Packit Service |
3a6627 |
pathItem.Patch = operation
|
|
Packit Service |
3a6627 |
case http.MethodPost:
|
|
Packit Service |
3a6627 |
pathItem.Post = operation
|
|
Packit Service |
3a6627 |
case http.MethodPut:
|
|
Packit Service |
3a6627 |
pathItem.Put = operation
|
|
Packit Service |
3a6627 |
case http.MethodTrace:
|
|
Packit Service |
3a6627 |
pathItem.Trace = operation
|
|
Packit Service |
3a6627 |
default:
|
|
Packit Service |
3a6627 |
panic(fmt.Errorf("Unsupported HTTP method '%s'", method))
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
|
|
Packit Service |
3a6627 |
func (pathItem *PathItem) Validate(c context.Context) error {
|
|
Packit Service |
3a6627 |
for _, operation := range pathItem.Operations() {
|
|
Packit Service |
3a6627 |
if err := operation.Validate(c); err != nil {
|
|
Packit Service |
3a6627 |
return err
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
return nil
|
|
Packit Service |
3a6627 |
}
|