feat: 请求响应结构体定义使用 $ref, 压缩文档体积
This commit is contained in:
@@ -208,16 +208,21 @@ func (g *Generate) AddApiDoc(docFlag string, apiMeta define.UriConfig, request a
|
||||
Value: &openapi3.RequestBody{
|
||||
Extensions: nil,
|
||||
Origin: nil,
|
||||
Description: "",
|
||||
Required: false,
|
||||
Description: "接口请求数据",
|
||||
Required: true,
|
||||
Content: map[string]*openapi3.MediaType{
|
||||
consts.MimeTypeJson: {
|
||||
Extensions: nil,
|
||||
Origin: nil,
|
||||
Schema: schemaData,
|
||||
Example: nil,
|
||||
Examples: nil,
|
||||
Encoding: nil,
|
||||
Schema: &openapi3.SchemaRef{
|
||||
Extensions: nil,
|
||||
Origin: nil,
|
||||
Ref: "#/components/schemas/" + strings.TrimLeft(requestType.String(), "*"),
|
||||
Value: nil,
|
||||
},
|
||||
Example: nil,
|
||||
Examples: nil,
|
||||
Encoding: nil,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -230,13 +235,12 @@ func (g *Generate) AddApiDoc(docFlag string, apiMeta define.UriConfig, request a
|
||||
if _, exist := g.docTable[docFlag].Components.Schemas[requestTypeStr]; !exist {
|
||||
g.docTable[docFlag].Components.Schemas[requestTypeStr] = schemaData
|
||||
}
|
||||
responseTypeStr := responseType.String()
|
||||
if _, exist := g.docTable[docFlag].Components.Schemas[responseTypeStr]; !exist {
|
||||
g.docTable[docFlag].Components.Schemas[responseTypeStr] = GenerateOpenAPISchema(responseType)
|
||||
}
|
||||
// 冗余处理结束
|
||||
}
|
||||
|
||||
responseTypeStr := responseType.String()
|
||||
if _, exist := g.docTable[docFlag].Components.Schemas[responseTypeStr]; !exist {
|
||||
g.docTable[docFlag].Components.Schemas[responseTypeStr] = GenerateOpenAPISchema(responseType)
|
||||
}
|
||||
desc := "请求成功"
|
||||
apiOperate.Responses.Set(fmt.Sprintf("%v", http.StatusOK), &openapi3.ResponseRef{
|
||||
Extensions: nil,
|
||||
@@ -251,10 +255,15 @@ func (g *Generate) AddApiDoc(docFlag string, apiMeta define.UriConfig, request a
|
||||
consts.MimeTypeJson: {
|
||||
Extensions: nil,
|
||||
Origin: nil,
|
||||
Schema: GenerateOpenAPISchema(responseType),
|
||||
Example: nil,
|
||||
Examples: nil,
|
||||
Encoding: nil,
|
||||
Schema: &openapi3.SchemaRef{
|
||||
Extensions: nil,
|
||||
Origin: nil,
|
||||
Ref: "#/components/schemas/" + strings.TrimLeft(responseTypeStr, "*"),
|
||||
Value: nil,
|
||||
},
|
||||
Example: nil,
|
||||
Examples: nil,
|
||||
Encoding: nil,
|
||||
},
|
||||
},
|
||||
Links: nil,
|
||||
|
||||
Reference in New Issue
Block a user