improve ExternalDocs feature for package goai

This commit is contained in:
John Guo 2022-03-28 15:21:58 +08:00
parent ec92d2b7f4
commit c6aba6da4d
3 changed files with 45 additions and 15 deletions

View File

@ -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",
}
)

View 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
}

View File

@ -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)
})
}