...

Source file src/github.com/go-openapi/spec/path_item_test.go

Documentation: github.com/go-openapi/spec

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

View as plain text