goai_example.go 867 B

123456789101112131415161718192021222324252627282930313233
  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. package goai
  7. import (
  8. "github.com/gogf/gf/v2/internal/json"
  9. )
  10. // Example is specified by OpenAPI/Swagger 3.0 standard.
  11. type Example struct {
  12. Summary string `json:"summary,omitempty"`
  13. Description string `json:"description,omitempty"`
  14. Value interface{} `json:"value,omitempty"`
  15. ExternalValue string `json:"externalValue,omitempty"`
  16. }
  17. type Examples map[string]*ExampleRef
  18. type ExampleRef struct {
  19. Ref string
  20. Value *Example
  21. }
  22. func (r ExampleRef) MarshalJSON() ([]byte, error) {
  23. if r.Ref != "" {
  24. return formatRefToBytes(r.Ref), nil
  25. }
  26. return json.Marshal(r.Value)
  27. }