Skip to content

Commit daca90f

Browse files
author
root
committed
rebuild servers
1 parent 3446e81 commit daca90f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+5998
-6047
lines changed

backend/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ make openapi-sync
5353

5454
Available commands:
5555

56-
- `make openapi-gen` — regenerate `ext-api.yaml` from `/api/ext/*` route source (machine-generated)
56+
- `make openapi-gen` — regenerate `ext-api.yaml` from custom route source (`/api/ext/*` + `/api/servers/*`, machine-generated)
5757
- `make openapi-merge` — merge `ext-api.yaml` + `native-api.yaml` into `api.yaml`
5858
- `make openapi-check` — fail when Ext route/spec drift or duplicate YAML keys exist
5959
- `make openapi-sync` — run generate + merge + check in order
@@ -89,7 +89,12 @@ backend/
8989

9090
## API Endpoints
9191

92-
### Custom Routes (all under `/api/ext/`)
92+
### Custom Routes
93+
94+
Custom business APIs use two prefixes:
95+
96+
- `/api/ext/*` for most extension domains
97+
- `/api/servers/*` for server runtime operations (shell/files/ops/containers)
9398

9499
| Method | Path | Auth | Description |
95100
|--------|------|------|-------------|

backend/cmd/openapi/gen.go

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,22 @@ func authForPath(path string, superuserVarPaths map[string]bool) string {
8181

8282
// route is a single discovered route entry.
8383
type route struct {
84-
method string
85-
path string
86-
handler string
87-
queryParams []string
88-
queryRequired map[string]bool
89-
headerParams []swaggerParamHint
90-
cookieParams []swaggerParamHint
84+
method string
85+
path string
86+
handler string
87+
queryParams []string
88+
queryRequired map[string]bool
89+
headerParams []swaggerParamHint
90+
cookieParams []swaggerParamHint
9191
formDataParams []swaggerParamHint
92-
bodyRequired *bool
93-
successCodes []int
94-
failureCodes []int
95-
markerGroup string
96-
markerSummary string
97-
markerAuth string
98-
summary string
99-
description string
92+
bodyRequired *bool
93+
successCodes []int
94+
failureCodes []int
95+
markerGroup string
96+
markerSummary string
97+
markerAuth string
98+
summary string
99+
description string
100100
}
101101

102102
type swaggerParamHint struct {
@@ -133,8 +133,13 @@ func scanFile(filePath string) ([]route, map[string]bool) {
133133
handlerSummaries := extractHandlerSummaries(string(data))
134134
handlerDescriptions := extractHandlerDescriptions(string(data))
135135

136+
defaultG := "/api/ext"
137+
if strings.HasPrefix(filepath.Base(filePath), "server") {
138+
defaultG = "/api/servers"
139+
}
140+
136141
vars := map[string]string{
137-
"g": "/api/ext",
142+
"g": defaultG,
138143
"se": "",
139144
"r": "",
140145
}
@@ -1140,6 +1145,24 @@ func summaryFrom(method, path string) string {
11401145
return strings.TrimSpace(action + " " + strings.Join(clean, " "))
11411146
}
11421147

1148+
func sanitizeContentText(raw string) string {
1149+
text := strings.TrimSpace(raw)
1150+
if text == "" {
1151+
return ""
1152+
}
1153+
text = strings.ReplaceAll(text, ":", " ")
1154+
text = strings.ReplaceAll(text, ":", " ")
1155+
text = strings.Join(strings.Fields(text), " ")
1156+
return text
1157+
}
1158+
1159+
func yamlQuotedScalar(raw string) string {
1160+
text := strings.TrimSpace(raw)
1161+
text = strings.ReplaceAll(text, `\`, `\\`)
1162+
text = strings.ReplaceAll(text, `"`, `\"`)
1163+
return "\"" + text + "\""
1164+
}
1165+
11431166
func operationID(method, path string) string {
11441167
clean := strings.ToLower(path)
11451168
clean = strings.ReplaceAll(clean, "/", "_")
@@ -1220,13 +1243,13 @@ func runGen() error {
12201243
out.WriteString("tags:\n")
12211244
for _, tag := range tags {
12221245
name := strings.TrimSpace(tag.Group)
1223-
desc := strings.TrimSpace(tag.Description)
1246+
desc := sanitizeContentText(tag.Description)
12241247
if name == "" {
12251248
continue
12261249
}
12271250
fmt.Fprintf(&out, " - name: %s\n", name)
12281251
if desc != "" {
1229-
fmt.Fprintf(&out, " description: %s\n", desc)
1252+
fmt.Fprintf(&out, " description: %s\n", yamlQuotedScalar(desc))
12301253
}
12311254
}
12321255
out.WriteString("\n")
@@ -1284,14 +1307,12 @@ func runGen() error {
12841307
} else if strings.TrimSpace(op.markerSummary) != "" {
12851308
resolvedSummary = strings.TrimSpace(op.markerSummary)
12861309
}
1310+
resolvedSummary = sanitizeContentText(resolvedSummary)
12871311
block = strings.Replace(block, " summary: "+summaryFrom(m, p), " summary: "+resolvedSummary, 1)
12881312
// Inject description after summary line if @Description is set
12891313
if strings.TrimSpace(op.description) != "" {
1290-
desc := strings.TrimSpace(op.description)
1291-
// Escape for YAML: wrap in double quotes, escape inner quotes and backslashes
1292-
desc = strings.ReplaceAll(desc, `\`, `\\`)
1293-
desc = strings.ReplaceAll(desc, `"`, `\"`)
1294-
block = strings.Replace(block, " summary: "+resolvedSummary+"\n", " summary: "+resolvedSummary+"\n description: \""+desc+"\"\n", 1)
1314+
desc := sanitizeContentText(op.description)
1315+
block = strings.Replace(block, " summary: "+resolvedSummary+"\n", " summary: "+resolvedSummary+"\n description: "+yamlQuotedScalar(desc)+"\n", 1)
12951316
}
12961317
out.WriteString(block)
12971318
}

0 commit comments

Comments
 (0)