http urls monitor.

tag.go 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. // TagProps describe a tag entry in the top level tags section of a swagger spec
  21. type TagProps struct {
  22. Description string `json:"description,omitempty"`
  23. Name string `json:"name,omitempty"`
  24. ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
  25. }
  26. // NewTag creates a new tag
  27. func NewTag(name, description string, externalDocs *ExternalDocumentation) Tag {
  28. return Tag{TagProps: TagProps{description, name, externalDocs}}
  29. }
  30. // Tag allows adding meta data to a single tag that is used by the [Operation Object](http://goo.gl/8us55a#operationObject).
  31. // It is not mandatory to have a Tag Object per tag used there.
  32. //
  33. // For more information: http://goo.gl/8us55a#tagObject
  34. type Tag struct {
  35. VendorExtensible
  36. TagProps
  37. }
  38. // JSONLookup implements an interface to customize json pointer lookup
  39. func (t Tag) JSONLookup(token string) (interface{}, error) {
  40. if ex, ok := t.Extensions[token]; ok {
  41. return &ex, nil
  42. }
  43. r, _, err := jsonpointer.GetForToken(t.TagProps, token)
  44. return r, err
  45. }
  46. // MarshalJSON marshal this to JSON
  47. func (t Tag) MarshalJSON() ([]byte, error) {
  48. b1, err := json.Marshal(t.TagProps)
  49. if err != nil {
  50. return nil, err
  51. }
  52. b2, err := json.Marshal(t.VendorExtensible)
  53. if err != nil {
  54. return nil, err
  55. }
  56. return swag.ConcatJSON(b1, b2), nil
  57. }
  58. // UnmarshalJSON marshal this from JSON
  59. func (t *Tag) UnmarshalJSON(data []byte) error {
  60. if err := json.Unmarshal(data, &t.TagProps); err != nil {
  61. return err
  62. }
  63. return json.Unmarshal(data, &t.VendorExtensible)
  64. }