...

Source file src/github.com/go-openapi/spec/contact_info.go

Documentation: github.com/go-openapi/spec

     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  
    15  package spec
    16  
    17  import (
    18  	"encoding/json"
    19  
    20  	"github.com/go-openapi/swag"
    21  )
    22  
    23  // ContactInfo contact information for the exposed API.
    24  //
    25  // For more information: http://goo.gl/8us55a#contactObject
    26  type ContactInfo struct {
    27  	ContactInfoProps
    28  	VendorExtensible
    29  }
    30  
    31  // ContactInfoProps hold the properties of a ContactInfo object
    32  type ContactInfoProps struct {
    33  	Name  string `json:"name,omitempty"`
    34  	URL   string `json:"url,omitempty"`
    35  	Email string `json:"email,omitempty"`
    36  }
    37  
    38  // UnmarshalJSON hydrates ContactInfo from json
    39  func (c *ContactInfo) UnmarshalJSON(data []byte) error {
    40  	if err := json.Unmarshal(data, &c.ContactInfoProps); err != nil {
    41  		return err
    42  	}
    43  	return json.Unmarshal(data, &c.VendorExtensible)
    44  }
    45  
    46  // MarshalJSON produces ContactInfo as json
    47  func (c ContactInfo) MarshalJSON() ([]byte, error) {
    48  	b1, err := json.Marshal(c.ContactInfoProps)
    49  	if err != nil {
    50  		return nil, err
    51  	}
    52  	b2, err := json.Marshal(c.VendorExtensible)
    53  	if err != nil {
    54  		return nil, err
    55  	}
    56  	return swag.ConcatJSON(b1, b2), nil
    57  }
    58  

View as plain text