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 spec
16
17import (
18	"encoding/json"
19
20	"github.com/go-openapi/swag"
21)
22
23// PathItemProps the path item specific properties
24type PathItemProps struct {
25	Get        *Operation  `json:"get,omitempty"`
26	Put        *Operation  `json:"put,omitempty"`
27	Post       *Operation  `json:"post,omitempty"`
28	Delete     *Operation  `json:"delete,omitempty"`
29	Options    *Operation  `json:"options,omitempty"`
30	Head       *Operation  `json:"head,omitempty"`
31	Patch      *Operation  `json:"patch,omitempty"`
32	Parameters []Parameter `json:"parameters,omitempty"`
33}
34
35// PathItem describes the operations available on a single path.
36// A Path Item may be empty, due to [ACL constraints](http://goo.gl/8us55a#securityFiltering).
37// The path itself is still exposed to the documentation viewer but they will
38// not know which operations and parameters are available.
39//
40// For more information: http://goo.gl/8us55a#pathItemObject
41type PathItem struct {
42	Refable
43	VendorExtensible
44	PathItemProps
45}
46
47// UnmarshalJSON hydrates this items instance with the data from JSON
48func (p *PathItem) UnmarshalJSON(data []byte) error {
49	if err := json.Unmarshal(data, &p.Refable); err != nil {
50		return err
51	}
52	if err := json.Unmarshal(data, &p.VendorExtensible); err != nil {
53		return err
54	}
55	return json.Unmarshal(data, &p.PathItemProps)
56}
57
58// MarshalJSON converts this items object to JSON
59func (p PathItem) MarshalJSON() ([]byte, error) {
60	b3, err := json.Marshal(p.Refable)
61	if err != nil {
62		return nil, err
63	}
64	b4, err := json.Marshal(p.VendorExtensible)
65	if err != nil {
66		return nil, err
67	}
68	b5, err := json.Marshal(p.PathItemProps)
69	if err != nil {
70		return nil, err
71	}
72	concated := swag.ConcatJSON(b3, b4, b5)
73	return concated, nil
74}
75