mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-26 13:07:14 +00:00
feat(api-docs): generate OpenAPI components/schemas from Go structs
A new emit_jsonschema.go walks the same allow-listed structs as the zod/types/examples emitters and writes generated/schemas.ts (SCHEMAS). build-openapi mounts it under components.schemas and points each typed response obj at a $ref instead of an untyped {} blob, so Swagger renders real models and openapi-generator can emit clients.
Also add a vitest guard that safeParses every EXAMPLES entry against its generated zod schema, reviving the previously unused generated/zod.ts and catching drift between the example and schema emitters.
This commit is contained in:
@@ -106,6 +106,10 @@ func run(root, outDir string) error {
|
||||
if err := emitExamples(examplesBuf, schemas, aliases); err != nil {
|
||||
return err
|
||||
}
|
||||
schemasBuf := &bytes.Buffer{}
|
||||
if err := emitJSONSchema(schemasBuf, schemas, aliases); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.WriteFile(filepath.Join(target, "zod.ts"), zodBuf.Bytes(), 0o644); err != nil {
|
||||
return err
|
||||
@@ -116,6 +120,9 @@ func run(root, outDir string) error {
|
||||
if err := os.WriteFile(filepath.Join(target, "examples.ts"), examplesBuf.Bytes(), 0o644); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(target, "schemas.ts"), schemasBuf.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