mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 04:07:47 +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 *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",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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定义,透传到底层"`
|
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)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user