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	"testing"
20
21	"github.com/stretchr/testify/assert"
22)
23
24var pathItem = PathItem{
25	Refable: Refable{Ref: MustCreateRef("Dog")},
26	VendorExtensible: VendorExtensible{
27		Extensions: map[string]interface{}{
28			"x-framework": "go-swagger",
29		},
30	},
31	PathItemProps: PathItemProps{
32		Get: &Operation{
33			OperationProps: OperationProps{Description: "get operation description"},
34		},
35		Put: &Operation{
36			OperationProps: OperationProps{Description: "put operation description"},
37		},
38		Post: &Operation{
39			OperationProps: OperationProps{Description: "post operation description"},
40		},
41		Delete: &Operation{
42			OperationProps: OperationProps{Description: "delete operation description"},
43		},
44		Options: &Operation{
45			OperationProps: OperationProps{Description: "options operation description"},
46		},
47		Head: &Operation{
48			OperationProps: OperationProps{Description: "head operation description"},
49		},
50		Patch: &Operation{
51			OperationProps: OperationProps{Description: "patch operation description"},
52		},
53		Parameters: []Parameter{
54			{
55				ParamProps: ParamProps{In: "path"},
56			},
57		},
58	},
59}
60
61const pathItemJSON = `{
62	"$ref": "Dog",
63	"x-framework": "go-swagger",
64	"get": { "description": "get operation description" },
65	"put": { "description": "put operation description" },
66	"post": { "description": "post operation description" },
67	"delete": { "description": "delete operation description" },
68	"options": { "description": "options operation description" },
69	"head": { "description": "head operation description" },
70	"patch": { "description": "patch operation description" },
71	"parameters": [{"in":"path"}]
72}`
73
74func TestIntegrationPathItem(t *testing.T) {
75	var actual PathItem
76	if assert.NoError(t, json.Unmarshal([]byte(pathItemJSON), &actual)) {
77		assert.EqualValues(t, actual, pathItem)
78	}
79
80	assertParsesJSON(t, pathItemJSON, pathItem)
81}
82