本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.6KB

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