1 // Copyright 2015 go-swagger maintainers
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
20 "github.com/go-openapi/jsonpointer"
21 "github.com/go-openapi/swag"
24 // TagProps describe a tag entry in the top level tags section of a swagger spec
25 type TagProps struct {
26 Description string `json:"description,omitempty"`
27 Name string `json:"name,omitempty"`
28 ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
31 // NewTag creates a new tag
32 func NewTag(name, description string, externalDocs *ExternalDocumentation) Tag {
33 return Tag{TagProps: TagProps{Description: description, Name: name, ExternalDocs: externalDocs}}
36 // Tag allows adding meta data to a single tag that is used by the
37 // [Operation Object](http://goo.gl/8us55a#operationObject).
38 // It is not mandatory to have a Tag Object per tag used there.
40 // For more information: http://goo.gl/8us55a#tagObject
46 // JSONLookup implements an interface to customize json pointer lookup
47 func (t Tag) JSONLookup(token string) (interface{}, error) {
48 if ex, ok := t.Extensions[token]; ok {
52 r, _, err := jsonpointer.GetForToken(t.TagProps, token)
56 // MarshalJSON marshal this to JSON
57 func (t Tag) MarshalJSON() ([]byte, error) {
58 b1, err := json.Marshal(t.TagProps)
62 b2, err := json.Marshal(t.VendorExtensible)
66 return swag.ConcatJSON(b1, b2), nil
69 // UnmarshalJSON marshal this from JSON
70 func (t *Tag) UnmarshalJSON(data []byte) error {
71 if err := json.Unmarshal(data, &t.TagProps); err != nil {
74 return json.Unmarshal(data, &t.VendorExtensible)