openapi格式的文档基础生成 #3
@ -253,7 +253,7 @@ type Example struct {
|
||||
//
|
||||
// Date : 17:38 2024/7/19
|
||||
type Response struct {
|
||||
Description string `json:"description,omitempty"` // 必选. 对响应的简短描述。CommonMark syntax可以被用来呈现富文本格式.
|
||||
Description string `json:"description" required:"true"` // 必选. 对响应的简短描述。CommonMark syntax可以被用来呈现富文本格式.
|
||||
Headers map[string]*Header `json:"headers,omitempty"` // 映射HTTP头名称到其定义。RFC7230 规定了HTTP头名称不区分大小写。如果一个响应头使用"Content-Type"作为HTTP头名称,它会被忽略。
|
||||
Content map[string]*Media `json:"content,omitempty"` // 一个包含描述预期响应负载的映射。使用 media type 或 media type range 作为键,以响应的描述作为值。当一个响应匹配多个键时,只有最明确的键才适用。比如:text/plain 会覆盖 text/*
|
||||
Ref string `json:"$ref,omitempty"` // 引用描述
|
||||
@ -270,7 +270,7 @@ type Info struct {
|
||||
TermsOfService string `json:"termsOfService,omitempty"` // 指向服务条款的 URL 地址,必须是 URL 地址格式。
|
||||
Contact *Contact `json:"contact,omitempty,omitempty"` // 联系方式
|
||||
License *License `json:"license,omitempty"` // 开源协议
|
||||
Version string `json:"version,omitempty" required:"true"` // 必选. API 文档的版本信息(注意:这个版本和开放 API 规范版本没有任何关系)。
|
||||
Version string `json:"version" required:"true"` // 必选. API 文档的版本信息(注意:这个版本和开放 API 规范版本没有任何关系)。
|
||||
}
|
||||
|
||||
// Contact 联系人信息
|
||||
|
@ -31,9 +31,12 @@ func NewOpenapiDoc(info *define.Info, servers []*define.ServerItem) *Generate {
|
||||
TermsOfService: "",
|
||||
Contact: nil,
|
||||
License: nil,
|
||||
Version: "",
|
||||
Version: "0.0.1",
|
||||
}
|
||||
}
|
||||
if len(info.Version) == 0 {
|
||||
info.Version = "0.0.1"
|
||||
}
|
||||
if nil == info.License {
|
||||
info.License = &define.License{
|
||||
Name: consts.LicenseApache20,
|
||||
@ -306,9 +309,9 @@ func (g *Generate) AddComponentsSchema(schemaName string, inputType reflect.Type
|
||||
inputType.Field(i).Type.Kind() == reflect.Map ||
|
||||
inputType.Field(i).Type.Kind() == reflect.Array ||
|
||||
inputType.Field(i).Type.Kind() == reflect.Slice {
|
||||
g.AddComponentsSchema(inputType.PkgPath(), inputType.Field(i).Type)
|
||||
g.AddComponentsSchema(schemaName+inputType.Field(i).Name, inputType.Field(i).Type)
|
||||
} else {
|
||||
g.docData.Components.Schemas[schemaName].Properties[inputType.Field(i).Type.String()] = &define.Property{
|
||||
g.docData.Components.Schemas[schemaName].Properties[inputType.Field(i).Name] = &define.Property{
|
||||
Type: "string",
|
||||
Format: inputType.Field(i).Type.String(),
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user