mirror of
https://gitee.com/johng/gf.git
synced 2024-11-30 03:07:45 +08:00
improve ExternalDocs feature for package goai
This commit is contained in:
parent
ec92d2b7f4
commit
c6aba6da4d
@ -36,12 +36,6 @@ type OpenApiV3 struct {
|
||||
ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"`
|
||||
}
|
||||
|
||||
// ExternalDocs is specified by OpenAPI/Swagger standard version 3.0.
|
||||
type ExternalDocs struct {
|
||||
URL string `json:"url,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
}
|
||||
|
||||
const (
|
||||
HttpMethodGet = `GET`
|
||||
HttpMethodPut = `PUT`
|
||||
@ -95,13 +89,14 @@ var (
|
||||
defaultReadContentTypes = []string{`application/json`}
|
||||
defaultWriteContentTypes = []string{`application/json`}
|
||||
shortTypeMapForTag = map[string]string{
|
||||
"d": "default",
|
||||
"sum": "summary",
|
||||
"sm": "summary",
|
||||
"des": "description",
|
||||
"dc": "description",
|
||||
"eg": "example",
|
||||
"egs": "examples",
|
||||
"d": "Default",
|
||||
"sum": "Summary",
|
||||
"sm": "Summary",
|
||||
"des": "Description",
|
||||
"dc": "Description",
|
||||
"eg": "Example",
|
||||
"egs": "Examples",
|
||||
"ed": "ExternalDocs",
|
||||
}
|
||||
)
|
||||
|
||||
|
35
protocol/goai/goai_external_docs.go
Normal file
35
protocol/goai/goai_external_docs.go
Normal file
@ -0,0 +1,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
|
||||
}
|
@ -816,7 +816,7 @@ func Test_Properties_In_Sequence(t *testing.T) {
|
||||
ClusterPreset string `dc:"业务自定义Cluster定义,透传到底层"`
|
||||
Engine string `dc:"引擎名称,例如:TxLightning"`
|
||||
Version string `dc:"引擎版本,例如:10.3.213 (兼容ClickHouse 21.3.12)"`
|
||||
SkipUpdateStatus bool `dc:"是否跳过状态更新,继续保持creating"`
|
||||
SkipUpdateStatus bool `dc:"是否跳过状态更新,继续保持creating" ed:"http://goframe.org"`
|
||||
}
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
@ -828,6 +828,6 @@ func Test_Properties_In_Sequence(t *testing.T) {
|
||||
Object: req,
|
||||
})
|
||||
t.AssertNil(err)
|
||||
//fmt.Println(oai)
|
||||
fmt.Println(oai)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user