mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-11 00:40:00 +08:00
goctl: v1.8.4-beta (#4890)
This commit is contained in:
@@ -49,6 +49,7 @@ const (
|
|||||||
propertyKeySchemes = "schemes"
|
propertyKeySchemes = "schemes"
|
||||||
propertyKeyTags = "tags"
|
propertyKeyTags = "tags"
|
||||||
propertyKeySummary = "summary"
|
propertyKeySummary = "summary"
|
||||||
|
propertyKeyGroup = "group"
|
||||||
propertyKeyOperationId = "operationId"
|
propertyKeyOperationId = "operationId"
|
||||||
propertyKeyDeprecated = "deprecated"
|
propertyKeyDeprecated = "deprecated"
|
||||||
propertyKeyPrefix = "prefix"
|
propertyKeyPrefix = "prefix"
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ type (
|
|||||||
summary: "query 类型接口集合" // 对应 swagger 的 summary
|
summary: "query 类型接口集合" // 对应 swagger 的 summary
|
||||||
prefix: v1
|
prefix: v1
|
||||||
authType: apiKey // 指定该路由使用的鉴权类型,值为 securityDefinitionsFromJson 中定义的名称
|
authType: apiKey // 指定该路由使用的鉴权类型,值为 securityDefinitionsFromJson 中定义的名称
|
||||||
|
group:"demo"
|
||||||
)
|
)
|
||||||
service Swagger {
|
service Swagger {
|
||||||
@doc (
|
@doc (
|
||||||
|
|||||||
@@ -34,23 +34,6 @@ func parametersFromType(ctx Context, method string, tp apiSpec.Type) []spec.Para
|
|||||||
if !ok {
|
if !ok {
|
||||||
return []spec.Parameter{}
|
return []spec.Parameter{}
|
||||||
}
|
}
|
||||||
structName, ok := isPostJson(ctx, method, tp)
|
|
||||||
if ok {
|
|
||||||
return []spec.Parameter{
|
|
||||||
{
|
|
||||||
ParamProps: spec.ParamProps{
|
|
||||||
In: paramsInBody,
|
|
||||||
Name: paramsInBody,
|
|
||||||
Required: true,
|
|
||||||
Schema: &spec.Schema{
|
|
||||||
SchemaProps: spec.SchemaProps{
|
|
||||||
Ref: spec.MustCreateRef(getRefName(structName)),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
resp []spec.Parameter
|
resp []spec.Parameter
|
||||||
@@ -197,20 +180,38 @@ func parametersFromType(ctx Context, method string, tp apiSpec.Type) []spec.Para
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
if len(properties) > 0 {
|
if len(properties) > 0 {
|
||||||
resp = append(resp, spec.Parameter{
|
if ctx.UseDefinitions {
|
||||||
ParamProps: spec.ParamProps{
|
structName, ok := isPostJson(ctx, method, tp)
|
||||||
In: paramsInBody,
|
if ok {
|
||||||
Name: paramsInBody,
|
resp = append(resp, spec.Parameter{
|
||||||
Required: true,
|
ParamProps: spec.ParamProps{
|
||||||
Schema: &spec.Schema{
|
In: paramsInBody,
|
||||||
SchemaProps: spec.SchemaProps{
|
Name: paramsInBody,
|
||||||
Type: typeFromGoType(ctx, structType),
|
Required: true,
|
||||||
Properties: properties,
|
Schema: &spec.Schema{
|
||||||
Required: requiredFields,
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Ref: spec.MustCreateRef(getRefName(structName)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
resp = append(resp, spec.Parameter{
|
||||||
|
ParamProps: spec.ParamProps{
|
||||||
|
In: paramsInBody,
|
||||||
|
Name: paramsInBody,
|
||||||
|
Required: true,
|
||||||
|
Schema: &spec.Schema{
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Type: typeFromGoType(ctx, structType),
|
||||||
|
Properties: properties,
|
||||||
|
Required: requiredFields,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
})
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/go-openapi/spec"
|
"github.com/go-openapi/spec"
|
||||||
apiSpec "github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
apiSpec "github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
||||||
|
"github.com/zeromicro/go-zero/tools/goctl/util/stringx"
|
||||||
)
|
)
|
||||||
|
|
||||||
func spec2Paths(ctx Context, srv apiSpec.Service) *spec.Paths {
|
func spec2Paths(ctx Context, srv apiSpec.Service) *spec.Paths {
|
||||||
@@ -70,6 +71,12 @@ func spec2Path(ctx Context, group apiSpec.Group, route apiSpec.Route) spec.PathI
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
groupName := getStringFromKVOrDefault(group.Annotation.Properties, propertyKeyGroup, "")
|
||||||
|
operationId := route.Handler
|
||||||
|
if len(groupName) > 0 {
|
||||||
|
operationId = stringx.From(groupName + "_" + route.Handler).ToCamel()
|
||||||
|
}
|
||||||
|
operationId = stringx.From(operationId).Untitle()
|
||||||
op := &spec.Operation{
|
op := &spec.Operation{
|
||||||
OperationProps: spec.OperationProps{
|
OperationProps: spec.OperationProps{
|
||||||
Description: getStringFromKVOrDefault(route.AtDoc.Properties, propertyKeyDescription, ""),
|
Description: getStringFromKVOrDefault(route.AtDoc.Properties, propertyKeyDescription, ""),
|
||||||
@@ -78,10 +85,10 @@ func spec2Path(ctx Context, group apiSpec.Group, route apiSpec.Route) spec.PathI
|
|||||||
Schemes: getListFromInfoOrDefault(route.AtDoc.Properties, propertyKeySchemes, []string{schemeHttps}),
|
Schemes: getListFromInfoOrDefault(route.AtDoc.Properties, propertyKeySchemes, []string{schemeHttps}),
|
||||||
Tags: getListFromInfoOrDefault(group.Annotation.Properties, propertyKeyTags, getListFromInfoOrDefault(group.Annotation.Properties, propertyKeySummary, []string{})),
|
Tags: getListFromInfoOrDefault(group.Annotation.Properties, propertyKeyTags, getListFromInfoOrDefault(group.Annotation.Properties, propertyKeySummary, []string{})),
|
||||||
Summary: getStringFromKVOrDefault(route.AtDoc.Properties, propertyKeySummary, getFirstUsableString(route.AtDoc.Text, route.Handler)),
|
Summary: getStringFromKVOrDefault(route.AtDoc.Properties, propertyKeySummary, getFirstUsableString(route.AtDoc.Text, route.Handler)),
|
||||||
ID: getStringFromKVOrDefault(route.AtDoc.Properties, propertyKeyOperationId, getFirstUsableString(route.AtDoc.Text, route.Handler)),
|
ID: operationId,
|
||||||
Deprecated: getBoolFromKVOrDefault(route.AtDoc.Properties, propertyKeyDeprecated, false),
|
Deprecated: getBoolFromKVOrDefault(route.AtDoc.Properties, propertyKeyDeprecated, false),
|
||||||
Security: security,
|
|
||||||
Parameters: parametersFromType(ctx, route.Method, route.RequestType),
|
Parameters: parametersFromType(ctx, route.Method, route.RequestType),
|
||||||
|
Security: security,
|
||||||
Responses: jsonResponseFromType(ctx, route.AtDoc, route.ResponseType),
|
Responses: jsonResponseFromType(ctx, route.AtDoc, route.ResponseType),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,19 @@ func propertiesFromType(ctx Context, tp apiSpec.Type) (spec.SchemaProperties, []
|
|||||||
example, defaultValue any
|
example, defaultValue any
|
||||||
enum []any
|
enum []any
|
||||||
)
|
)
|
||||||
|
pathTag, _ := tag.Get(tagPath)
|
||||||
|
if pathTag != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
formTag, _ := tag.Get(tagForm)
|
||||||
|
if formTag != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
headerTag, _ := tag.Get(tagHeader)
|
||||||
|
if headerTag != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
jsonTag, _ := tag.Get(tagJson)
|
jsonTag, _ := tag.Get(tagJson)
|
||||||
if jsonTag != nil {
|
if jsonTag != nil {
|
||||||
jsonTagString = jsonTag.Name
|
jsonTagString = jsonTag.Name
|
||||||
|
|||||||
Reference in New Issue
Block a user