mirror of
https://github.com/go-home-admin/toolset.git
synced 2026-04-22 16:17:04 +08:00
fixed: swagger
This commit is contained in:
@@ -113,12 +113,15 @@ func (SwaggerCommand) Execute(input command.Input) {
|
||||
for _, service := range fileParser.Services {
|
||||
var prefix string
|
||||
if routeGroup, ok := service.Opt["http.RouteGroup"]; ok {
|
||||
prefix = "/$[" + routeGroup.Val + "]"
|
||||
prefix = "$[" + routeGroup.Val + "]"
|
||||
if routeGroup.Doc != "" {
|
||||
re := regexp.MustCompile(`(?i)@prefix=(\w+)`)
|
||||
re := regexp.MustCompile(`(?i)@prefix=(.*)`)
|
||||
match := re.FindStringSubmatch(routeGroup.Doc)
|
||||
if match != nil {
|
||||
prefix = "/" + match[1]
|
||||
prefix = match[1]
|
||||
if !strings.HasPrefix(prefix, "/") {
|
||||
prefix = "/" + prefix
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,6 +337,7 @@ func messageToParameters(message string, nowDirProtoc []parser.ProtocFileParser,
|
||||
for _, option := range protocMessage.Attr {
|
||||
doc, isRequired := filterRequired(option.Doc)
|
||||
doc, example := filterExample(doc, option.Ty)
|
||||
doc = filterLanguage(doc)
|
||||
doc = getTitle(doc)
|
||||
if option.Repeated {
|
||||
if isProtoBaseType(option.Ty) {
|
||||
@@ -652,8 +656,8 @@ func filterRequired(doc string) (string, bool) {
|
||||
re := regexp.MustCompile(`(?i)[/\s]*@tag\("binding"[,\s"]+([^"]+)"\)\s*`)
|
||||
re2 := regexp.MustCompile(`(?i)required`)
|
||||
for _, s := range arr {
|
||||
match := re.FindStringSubmatch(s)
|
||||
if len(match) == 2 && re2.MatchString(arr[1]) {
|
||||
matches := re.FindStringSubmatch(s)
|
||||
if len(matches) == 2 && re2.MatchString(matches[1]) {
|
||||
isRequired = true
|
||||
} else {
|
||||
newArr = append(newArr, s)
|
||||
@@ -772,6 +776,8 @@ func parseParamInPath(option parser.Option) (params openapi.Parameters) {
|
||||
case "lang":
|
||||
if m[2] == language {
|
||||
correctLang = true
|
||||
} else {
|
||||
correctDoc = false
|
||||
}
|
||||
case "format":
|
||||
if correctDoc {
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
|
||||
### 2024-10-18 更新
|
||||
|
||||
1. 在路由组声明上一行加上注释`@prefix=xxx`即可指定当前protobuf文件生成的swagger的接口前缀为`xxx`,该注释仅文档使用,应与业务代码一致)
|
||||
1. 在路由组声明上一行加上注释`@prefix=xxx`即可指定当前protobuf文件生成的swagger的接口前缀为`xxx`,该注释仅文档使用,应与业务代码一致
|
||||
```
|
||||
// @prefix=api
|
||||
option (http.RouteGroup) = "api";
|
||||
|
||||
+1
-1
@@ -167,7 +167,7 @@ func IsSpaceAndEspecially(r rune) bool {
|
||||
// This property isn't the same as Z; special-case it.
|
||||
if uint32(r) <= unicode.MaxLatin1 {
|
||||
switch r {
|
||||
case '=', ';', '/', '\t', '\n', '\v', '\f', '\r', ' ', 0x85, 0xA0:
|
||||
case ';', '/', '\t', '\n', '\v', '\f', '\r', ' ', 0x85, 0xA0:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user