path_item.go 2.9 KB

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