Update parser.go

Support interface type
This commit is contained in:
MaxToby 2021-10-13 13:29:36 +08:00 committed by GitHub
parent cb37f89d87
commit 29d6aecb33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -58,8 +58,8 @@ func applyGenerate(p *plugin2.Plugin, host string, basePath string) (*swaggerObj
newSecDefValue.Type = "apiKey" newSecDefValue.Type = "apiKey"
newSecDefValue.In = "header" newSecDefValue.In = "header"
s.SecurityDefinitions["apiKey"] = newSecDefValue s.SecurityDefinitions["apiKey"] = newSecDefValue
s.Security = append(s.Security, swaggerSecurityRequirementObject{"apiKey": []string{}})
s.Security = append(s.Security, swaggerSecurityRequirementObject{"apiKey": []string{}})
requestResponseRefs := refMap{} requestResponseRefs := refMap{}
renderServiceRoutes(p.Api.Service, p.Api.Service.Groups, s.Paths, requestResponseRefs) renderServiceRoutes(p.Api.Service, p.Api.Service.Groups, s.Paths, requestResponseRefs)
@ -98,6 +98,7 @@ func renderServiceRoutes(service spec.Service, groups []spec.Group, paths swagge
continue continue
} }
tempKind := swaggerMapTypes[strings.Replace(member.Type.Name(), "[]", "", -1)] tempKind := swaggerMapTypes[strings.Replace(member.Type.Name(), "[]", "", -1)]
ftype, format, ok := primitiveSchema(tempKind, member.Type.Name()) ftype, format, ok := primitiveSchema(tempKind, member.Type.Name())
if !ok { if !ok {
ftype = tempKind.String() ftype = tempKind.String()
@ -163,9 +164,11 @@ func renderServiceRoutes(service spec.Service, groups []spec.Group, paths swagge
if value := group.GetAnnotation("group"); len(value) > 0 { if value := group.GetAnnotation("group"); len(value) > 0 {
tags = value tags = value
} }
if value := group.GetAnnotation("swtags"); len(value) > 0 { if value := group.GetAnnotation("swtags"); len(value) > 0 {
tags = value tags = value
} }
operationObject := &swaggerOperationObject{ operationObject := &swaggerOperationObject{
Tags: []string{tags}, Tags: []string{tags},
Parameters: parameters, Parameters: parameters,
@ -263,7 +266,7 @@ func schemaOfField(member spec.Member) swaggerSchemaObject {
ret := swaggerSchemaObject{} ret := swaggerSchemaObject{}
var core schemaCore var core schemaCore
// spew.Dump(member)
kind := swaggerMapTypes[member.Type.Name()] kind := swaggerMapTypes[member.Type.Name()]
var props *swaggerSchemaObjectProperties var props *swaggerSchemaObjectProperties
@ -277,9 +280,19 @@ func schemaOfField(member spec.Member) swaggerSchemaObject {
refTypeName := strings.Replace(member.Type.Name(), "[", "", 1) refTypeName := strings.Replace(member.Type.Name(), "[", "", 1)
refTypeName = strings.Replace(refTypeName, "]", "", 1) refTypeName = strings.Replace(refTypeName, "]", "", 1)
refTypeName = strings.Replace(refTypeName, "*", "", 1) refTypeName = strings.Replace(refTypeName, "*", "", 1)
refTypeName = strings.Replace(refTypeName, "{", "", 1)
refTypeName = strings.Replace(refTypeName, "}", "", 1)
// interface
if refTypeName == "interface" {
core = schemaCore{Type: "object"}
} else if refTypeName == "mapstringstring" {
core = schemaCore{Type: "object"}
} else {
core = schemaCore{ core = schemaCore{
Ref: "#/definitions/" + refTypeName, Ref: "#/definitions/" + refTypeName,
} }
}
case reflect.Slice: case reflect.Slice:
tempKind := swaggerMapTypes[strings.Replace(member.Type.Name(), "[]", "", -1)] tempKind := swaggerMapTypes[strings.Replace(member.Type.Name(), "[]", "", -1)]
ftype, format, ok := primitiveSchema(tempKind, member.Type.Name()) ftype, format, ok := primitiveSchema(tempKind, member.Type.Name())
@ -321,6 +334,9 @@ func schemaOfField(member spec.Member) swaggerSchemaObject {
Properties: props, Properties: props,
} }
} }
if strings.HasPrefix(member.Type.Name(), "map") {
fmt.Println("暂不支持map类型")
}
default: default:
ret = swaggerSchemaObject{ ret = swaggerSchemaObject{
schemaCore: core, schemaCore: core,