podman
87 строк · 2.6 Кб
1// Copyright 2015 go-swagger maintainers
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package spec16
17import (18"encoding/json"19
20"github.com/go-openapi/jsonpointer"21"github.com/go-openapi/swag"22)
23
24// PathItemProps the path item specific properties
25type PathItemProps struct {26Get *Operation `json:"get,omitempty"`27Put *Operation `json:"put,omitempty"`28Post *Operation `json:"post,omitempty"`29Delete *Operation `json:"delete,omitempty"`30Options *Operation `json:"options,omitempty"`31Head *Operation `json:"head,omitempty"`32Patch *Operation `json:"patch,omitempty"`33Parameters []Parameter `json:"parameters,omitempty"`34}
35
36// PathItem describes the operations available on a single path.
37// A Path Item may be empty, due to [ACL constraints](http://goo.gl/8us55a#securityFiltering).
38// The path itself is still exposed to the documentation viewer but they will
39// not know which operations and parameters are available.
40//
41// For more information: http://goo.gl/8us55a#pathItemObject
42type PathItem struct {43Refable
44VendorExtensible
45PathItemProps
46}
47
48// JSONLookup look up a value by the json property name
49func (p PathItem) JSONLookup(token string) (interface{}, error) {50if ex, ok := p.Extensions[token]; ok {51return &ex, nil52}53if token == jsonRef {54return &p.Ref, nil55}56r, _, err := jsonpointer.GetForToken(p.PathItemProps, token)57return r, err58}
59
60// UnmarshalJSON hydrates this items instance with the data from JSON
61func (p *PathItem) UnmarshalJSON(data []byte) error {62if err := json.Unmarshal(data, &p.Refable); err != nil {63return err64}65if err := json.Unmarshal(data, &p.VendorExtensible); err != nil {66return err67}68return json.Unmarshal(data, &p.PathItemProps)69}
70
71// MarshalJSON converts this items object to JSON
72func (p PathItem) MarshalJSON() ([]byte, error) {73b3, err := json.Marshal(p.Refable)74if err != nil {75return nil, err76}77b4, err := json.Marshal(p.VendorExtensible)78if err != nil {79return nil, err80}81b5, err := json.Marshal(p.PathItemProps)82if err != nil {83return nil, err84}85concated := swag.ConcatJSON(b3, b4, b5)86return concated, nil87}
88