-
Notifications
You must be signed in to change notification settings - Fork 0
/
goai_external_docs.go
35 lines (31 loc) · 961 Bytes
/
goai_external_docs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package goai
import (
"github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
)
// ExternalDocs is specified by OpenAPI/Swagger standard version 3.0.
type ExternalDocs struct {
URL string `json:"url,omitempty"`
Description string `json:"description,omitempty"`
}
func (ed *ExternalDocs) UnmarshalValue(value interface{}) error {
var valueBytes = gconv.Bytes(value)
if json.Valid(valueBytes) {
return json.UnmarshalUseNumber(valueBytes, ed)
}
var (
valueString = string(valueBytes)
valueArray = gstr.Split(valueString, "|")
)
ed.URL = valueArray[0]
if len(valueArray) > 1 {
ed.Description = valueArray[1]
}
return nil
}