mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-25 12:27:13 +00:00
feat(api-docs): generate response examples from Go structs; fix SS2022 PSK regen (#4996)
Stop hand-writing OpenAPI response examples, which kept drifting from the real payloads (clients/traffic missing fields, inbounds/list exposing userId which is json:"-", the fictional inbound-443 tag instead of the real in-<port>-<transport> form).
tools/openapigen now emits frontend/src/generated/examples.ts: a per-struct example instance built from type defaults, validate oneof/min bounds, and example: struct tags, with nested-ref expansion and a cycle guard. build-openapi.mjs composes the {success,obj} envelope from it for any endpoint annotated with responseSchema (+ responseSchemaArray for lists); the hand-written response is dropped for those. Service DTOs InboundOption/ApiTokenView/ProbeResultUI are added to the walker.
#4996: client password regeneration now produces a valid Shadowsocks 2022 PSK (correct base64 length per cipher) when an SS2022 inbound is attached, in both the single and bulk client forms; backend surfaces ssMethod on /inbounds/options so the UI can pick the right length.
Also: Swagger UI persists the Authorization token across reloads (persistAuthorization).
This commit is contained in:
@@ -69,6 +69,14 @@ func run(root, outDir string) error {
|
||||
"ClientTraffic",
|
||||
),
|
||||
},
|
||||
{
|
||||
Path: resolveRel(root, "web/service"),
|
||||
StructAllow: setOf(
|
||||
"InboundOption",
|
||||
"ApiTokenView",
|
||||
"ProbeResultUI",
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
schemas, aliases, err := walkPackages(requests)
|
||||
@@ -94,6 +102,10 @@ func run(root, outDir string) error {
|
||||
if err := emitTypes(typesBuf, schemas, aliases); err != nil {
|
||||
return err
|
||||
}
|
||||
examplesBuf := &bytes.Buffer{}
|
||||
if err := emitExamples(examplesBuf, schemas, aliases); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.WriteFile(filepath.Join(target, "zod.ts"), zodBuf.Bytes(), 0o644); err != nil {
|
||||
return err
|
||||
@@ -101,6 +113,9 @@ func run(root, outDir string) error {
|
||||
if err := os.WriteFile(filepath.Join(target, "types.ts"), typesBuf.Bytes(), 0o644); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(target, "examples.ts"), examplesBuf.Bytes(), 0o644); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("openapigen: wrote %d schemas to %s\n", len(schemas), target)
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user