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 *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 ( const (
HttpMethodGet = `GET` HttpMethodGet = `GET`
HttpMethodPut = `PUT` HttpMethodPut = `PUT`
@ -95,13 +89,14 @@ var (
defaultReadContentTypes = []string{`application/json`} defaultReadContentTypes = []string{`application/json`}
defaultWriteContentTypes = []string{`application/json`} defaultWriteContentTypes = []string{`application/json`}
shortTypeMapForTag = map[string]string{ shortTypeMapForTag = map[string]string{
"d": "default", "d": "Default",
"sum": "summary", "sum": "Summary",
"sm": "summary", "sm": "Summary",
"des": "description", "des": "Description",
"dc": "description", "dc": "Description",
"eg": "example", "eg": "Example",
"egs": "examples", "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定义透传到底层"` ClusterPreset string `dc:"业务自定义Cluster定义透传到底层"`
Engine string `dc:"引擎名称例如TxLightning"` Engine string `dc:"引擎名称例如TxLightning"`
Version string `dc:"引擎版本例如10.3.213 (兼容ClickHouse 21.3.12)"` 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) { gtest.C(t, func(t *gtest.T) {
var ( var (
@ -828,6 +828,6 @@ func Test_Properties_In_Sequence(t *testing.T) {
Object: req, Object: req,
}) })
t.AssertNil(err) t.AssertNil(err)
//fmt.Println(oai) fmt.Println(oai)
}) })
} }