github.com/gogf/gf/v2@v2.7.4/net/goai/goai_example.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package goai
     8  
     9  import (
    10  	"github.com/gogf/gf/v2/internal/json"
    11  )
    12  
    13  // Example is specified by OpenAPI/Swagger 3.0 standard.
    14  type Example struct {
    15  	Summary       string      `json:"summary,omitempty"`
    16  	Description   string      `json:"description,omitempty"`
    17  	Value         interface{} `json:"value,omitempty"`
    18  	ExternalValue string      `json:"externalValue,omitempty"`
    19  }
    20  
    21  type Examples map[string]*ExampleRef
    22  
    23  type ExampleRef struct {
    24  	Ref   string
    25  	Value *Example
    26  }
    27  
    28  func (r ExampleRef) MarshalJSON() ([]byte, error) {
    29  	if r.Ref != "" {
    30  		return formatRefToBytes(r.Ref), nil
    31  	}
    32  	return json.Marshal(r.Value)
    33  }