path_item_test.go 2.4 KB

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