forked from ebhomengo/niki
1
0
Fork 0
niki/vendor/github.com/go-openapi/spec/path_item.go

151 lines
2.6 KiB
Go
Raw Normal View History

2024-05-14 13:07:09 +00:00
// Copyright 2015 go-swagger maintainers
2024-05-14 13:07:09 +00:00
//
2024-05-14 13:07:09 +00:00
// Licensed under the Apache License, Version 2.0 (the "License");
2024-05-14 13:07:09 +00:00
// you may not use this file except in compliance with the License.
2024-05-14 13:07:09 +00:00
// You may obtain a copy of the License at
2024-05-14 13:07:09 +00:00
//
2024-05-14 13:07:09 +00:00
// http://www.apache.org/licenses/LICENSE-2.0
2024-05-14 13:07:09 +00:00
//
2024-05-14 13:07:09 +00:00
// Unless required by applicable law or agreed to in writing, software
2024-05-14 13:07:09 +00:00
// distributed under the License is distributed on an "AS IS" BASIS,
2024-05-14 13:07:09 +00:00
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2024-05-14 13:07:09 +00:00
// See the License for the specific language governing permissions and
2024-05-14 13:07:09 +00:00
// limitations under the License.
package spec
import (
"encoding/json"
"github.com/go-openapi/jsonpointer"
"github.com/go-openapi/swag"
)
// PathItemProps the path item specific properties
2024-05-14 13:07:09 +00:00
type PathItemProps struct {
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"`
2024-05-14 13:07:09 +00:00
Parameters []Parameter `json:"parameters,omitempty"`
}
// PathItem describes the operations available on a single path.
2024-05-14 13:07:09 +00:00
// A Path Item may be empty, due to [ACL constraints](http://goo.gl/8us55a#securityFiltering).
2024-05-14 13:07:09 +00:00
// The path itself is still exposed to the documentation viewer but they will
2024-05-14 13:07:09 +00:00
// not know which operations and parameters are available.
2024-05-14 13:07:09 +00:00
//
2024-05-14 13:07:09 +00:00
// For more information: http://goo.gl/8us55a#pathItemObject
2024-05-14 13:07:09 +00:00
type PathItem struct {
Refable
2024-05-14 13:07:09 +00:00
VendorExtensible
2024-05-14 13:07:09 +00:00
PathItemProps
}
// JSONLookup look up a value by the json property name
2024-05-14 13:07:09 +00:00
func (p PathItem) JSONLookup(token string) (interface{}, error) {
2024-05-14 13:07:09 +00:00
if ex, ok := p.Extensions[token]; ok {
2024-05-14 13:07:09 +00:00
return &ex, nil
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
if token == jsonRef {
2024-05-14 13:07:09 +00:00
return &p.Ref, nil
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
r, _, err := jsonpointer.GetForToken(p.PathItemProps, token)
2024-05-14 13:07:09 +00:00
return r, err
2024-05-14 13:07:09 +00:00
}
// UnmarshalJSON hydrates this items instance with the data from JSON
2024-05-14 13:07:09 +00:00
func (p *PathItem) UnmarshalJSON(data []byte) error {
2024-05-14 13:07:09 +00:00
if err := json.Unmarshal(data, &p.Refable); err != nil {
2024-05-14 13:07:09 +00:00
return err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
if err := json.Unmarshal(data, &p.VendorExtensible); err != nil {
2024-05-14 13:07:09 +00:00
return err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
return json.Unmarshal(data, &p.PathItemProps)
2024-05-14 13:07:09 +00:00
}
// MarshalJSON converts this items object to JSON
2024-05-14 13:07:09 +00:00
func (p PathItem) MarshalJSON() ([]byte, error) {
2024-05-14 13:07:09 +00:00
b3, err := json.Marshal(p.Refable)
2024-05-14 13:07:09 +00:00
if err != nil {
2024-05-14 13:07:09 +00:00
return nil, err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
b4, err := json.Marshal(p.VendorExtensible)
2024-05-14 13:07:09 +00:00
if err != nil {
2024-05-14 13:07:09 +00:00
return nil, err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
b5, err := json.Marshal(p.PathItemProps)
2024-05-14 13:07:09 +00:00
if err != nil {
2024-05-14 13:07:09 +00:00
return nil, err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
concated := swag.ConcatJSON(b3, b4, b5)
2024-05-14 13:07:09 +00:00
return concated, nil
2024-05-14 13:07:09 +00:00
}