2026-03-14 10:03:29 +00:00
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
|
|
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
feat: AX v0.8.0 — Core primitives, Result returns, zero disallowed imports
- api.go: errors.Is → core.Is
- openapi.go: Build returns core.Result, encoding/json → core.JSONMarshal
- export.go: rewrite with core.Fs, core.JSONUnmarshal, returns core.Result
- codegen.go: rewrite with c.Process(), core.Fs, App.Find — no os/exec
- sse.go: encoding/json → core.JSONMarshalString, fmt → core.Sprintf
- swagger.go: fmt → core.Sprintf, Build caller updated for core.Result
- middleware.go: strings → core.HasPrefix/SplitN/Lower
- authentik.go: strings → core.HasPrefix/TrimPrefix/Split/Trim/Contains
- brotli.go: strings → core.Contains
Transport boundary files (net/http, io for compression) retained.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 08:39:59 +00:00
|
|
|
core "dappco.re/go/core"
|
2026-03-14 10:03:29 +00:00
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
|
)
|
|
|
|
|
|
feat: AX v0.8.0 — Core primitives, Result returns, zero disallowed imports
- api.go: errors.Is → core.Is
- openapi.go: Build returns core.Result, encoding/json → core.JSONMarshal
- export.go: rewrite with core.Fs, core.JSONUnmarshal, returns core.Result
- codegen.go: rewrite with c.Process(), core.Fs, App.Find — no os/exec
- sse.go: encoding/json → core.JSONMarshalString, fmt → core.Sprintf
- swagger.go: fmt → core.Sprintf, Build caller updated for core.Result
- middleware.go: strings → core.HasPrefix/SplitN/Lower
- authentik.go: strings → core.HasPrefix/TrimPrefix/Split/Trim/Contains
- brotli.go: strings → core.Contains
Transport boundary files (net/http, io for compression) retained.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 08:39:59 +00:00
|
|
|
// ExportSpec generates the OpenAPI spec and writes it to a core.Fs path.
|
2026-03-14 10:03:29 +00:00
|
|
|
// Format must be "json" or "yaml".
|
feat: AX v0.8.0 — Core primitives, Result returns, zero disallowed imports
- api.go: errors.Is → core.Is
- openapi.go: Build returns core.Result, encoding/json → core.JSONMarshal
- export.go: rewrite with core.Fs, core.JSONUnmarshal, returns core.Result
- codegen.go: rewrite with c.Process(), core.Fs, App.Find — no os/exec
- sse.go: encoding/json → core.JSONMarshalString, fmt → core.Sprintf
- swagger.go: fmt → core.Sprintf, Build caller updated for core.Result
- middleware.go: strings → core.HasPrefix/SplitN/Lower
- authentik.go: strings → core.HasPrefix/TrimPrefix/Split/Trim/Contains
- brotli.go: strings → core.Contains
Transport boundary files (net/http, io for compression) retained.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 08:39:59 +00:00
|
|
|
func ExportSpec(path, format string, builder *SpecBuilder, groups []RouteGroup) core.Result {
|
|
|
|
|
r := builder.Build(groups)
|
|
|
|
|
if !r.OK {
|
|
|
|
|
return r
|
2026-03-14 10:03:29 +00:00
|
|
|
}
|
feat: AX v0.8.0 — Core primitives, Result returns, zero disallowed imports
- api.go: errors.Is → core.Is
- openapi.go: Build returns core.Result, encoding/json → core.JSONMarshal
- export.go: rewrite with core.Fs, core.JSONUnmarshal, returns core.Result
- codegen.go: rewrite with c.Process(), core.Fs, App.Find — no os/exec
- sse.go: encoding/json → core.JSONMarshalString, fmt → core.Sprintf
- swagger.go: fmt → core.Sprintf, Build caller updated for core.Result
- middleware.go: strings → core.HasPrefix/SplitN/Lower
- authentik.go: strings → core.HasPrefix/TrimPrefix/Split/Trim/Contains
- brotli.go: strings → core.Contains
Transport boundary files (net/http, io for compression) retained.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 08:39:59 +00:00
|
|
|
data := r.Value.([]byte)
|
2026-03-14 10:03:29 +00:00
|
|
|
|
|
|
|
|
switch format {
|
|
|
|
|
case "json":
|
feat: AX v0.8.0 — Core primitives, Result returns, zero disallowed imports
- api.go: errors.Is → core.Is
- openapi.go: Build returns core.Result, encoding/json → core.JSONMarshal
- export.go: rewrite with core.Fs, core.JSONUnmarshal, returns core.Result
- codegen.go: rewrite with c.Process(), core.Fs, App.Find — no os/exec
- sse.go: encoding/json → core.JSONMarshalString, fmt → core.Sprintf
- swagger.go: fmt → core.Sprintf, Build caller updated for core.Result
- middleware.go: strings → core.HasPrefix/SplitN/Lower
- authentik.go: strings → core.HasPrefix/TrimPrefix/Split/Trim/Contains
- brotli.go: strings → core.Contains
Transport boundary files (net/http, io for compression) retained.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 08:39:59 +00:00
|
|
|
return (&core.Fs{}).NewUnrestricted().Write(path, string(data))
|
2026-03-14 10:03:29 +00:00
|
|
|
case "yaml":
|
|
|
|
|
var obj any
|
feat: AX v0.8.0 — Core primitives, Result returns, zero disallowed imports
- api.go: errors.Is → core.Is
- openapi.go: Build returns core.Result, encoding/json → core.JSONMarshal
- export.go: rewrite with core.Fs, core.JSONUnmarshal, returns core.Result
- codegen.go: rewrite with c.Process(), core.Fs, App.Find — no os/exec
- sse.go: encoding/json → core.JSONMarshalString, fmt → core.Sprintf
- swagger.go: fmt → core.Sprintf, Build caller updated for core.Result
- middleware.go: strings → core.HasPrefix/SplitN/Lower
- authentik.go: strings → core.HasPrefix/TrimPrefix/Split/Trim/Contains
- brotli.go: strings → core.Contains
Transport boundary files (net/http, io for compression) retained.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 08:39:59 +00:00
|
|
|
if ur := core.JSONUnmarshal(data, &obj); !ur.OK {
|
|
|
|
|
return core.Result{Value: core.E("ExportSpec", "unmarshal spec", nil), OK: false}
|
2026-03-14 10:03:29 +00:00
|
|
|
}
|
feat: AX v0.8.0 — Core primitives, Result returns, zero disallowed imports
- api.go: errors.Is → core.Is
- openapi.go: Build returns core.Result, encoding/json → core.JSONMarshal
- export.go: rewrite with core.Fs, core.JSONUnmarshal, returns core.Result
- codegen.go: rewrite with c.Process(), core.Fs, App.Find — no os/exec
- sse.go: encoding/json → core.JSONMarshalString, fmt → core.Sprintf
- swagger.go: fmt → core.Sprintf, Build caller updated for core.Result
- middleware.go: strings → core.HasPrefix/SplitN/Lower
- authentik.go: strings → core.HasPrefix/TrimPrefix/Split/Trim/Contains
- brotli.go: strings → core.Contains
Transport boundary files (net/http, io for compression) retained.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 08:39:59 +00:00
|
|
|
b := core.NewBuilder()
|
|
|
|
|
enc := yaml.NewEncoder(b)
|
2026-03-14 10:03:29 +00:00
|
|
|
enc.SetIndent(2)
|
|
|
|
|
if err := enc.Encode(obj); err != nil {
|
feat: AX v0.8.0 — Core primitives, Result returns, zero disallowed imports
- api.go: errors.Is → core.Is
- openapi.go: Build returns core.Result, encoding/json → core.JSONMarshal
- export.go: rewrite with core.Fs, core.JSONUnmarshal, returns core.Result
- codegen.go: rewrite with c.Process(), core.Fs, App.Find — no os/exec
- sse.go: encoding/json → core.JSONMarshalString, fmt → core.Sprintf
- swagger.go: fmt → core.Sprintf, Build caller updated for core.Result
- middleware.go: strings → core.HasPrefix/SplitN/Lower
- authentik.go: strings → core.HasPrefix/TrimPrefix/Split/Trim/Contains
- brotli.go: strings → core.Contains
Transport boundary files (net/http, io for compression) retained.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 08:39:59 +00:00
|
|
|
return core.Result{Value: core.E("ExportSpec", "encode yaml", err), OK: false}
|
2026-03-14 10:03:29 +00:00
|
|
|
}
|
feat: AX v0.8.0 — Core primitives, Result returns, zero disallowed imports
- api.go: errors.Is → core.Is
- openapi.go: Build returns core.Result, encoding/json → core.JSONMarshal
- export.go: rewrite with core.Fs, core.JSONUnmarshal, returns core.Result
- codegen.go: rewrite with c.Process(), core.Fs, App.Find — no os/exec
- sse.go: encoding/json → core.JSONMarshalString, fmt → core.Sprintf
- swagger.go: fmt → core.Sprintf, Build caller updated for core.Result
- middleware.go: strings → core.HasPrefix/SplitN/Lower
- authentik.go: strings → core.HasPrefix/TrimPrefix/Split/Trim/Contains
- brotli.go: strings → core.Contains
Transport boundary files (net/http, io for compression) retained.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 08:39:59 +00:00
|
|
|
enc.Close()
|
|
|
|
|
return (&core.Fs{}).NewUnrestricted().Write(path, b.String())
|
2026-03-14 10:03:29 +00:00
|
|
|
default:
|
feat: AX v0.8.0 — Core primitives, Result returns, zero disallowed imports
- api.go: errors.Is → core.Is
- openapi.go: Build returns core.Result, encoding/json → core.JSONMarshal
- export.go: rewrite with core.Fs, core.JSONUnmarshal, returns core.Result
- codegen.go: rewrite with c.Process(), core.Fs, App.Find — no os/exec
- sse.go: encoding/json → core.JSONMarshalString, fmt → core.Sprintf
- swagger.go: fmt → core.Sprintf, Build caller updated for core.Result
- middleware.go: strings → core.HasPrefix/SplitN/Lower
- authentik.go: strings → core.HasPrefix/TrimPrefix/Split/Trim/Contains
- brotli.go: strings → core.Contains
Transport boundary files (net/http, io for compression) retained.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 08:39:59 +00:00
|
|
|
return core.Result{Value: core.E("ExportSpec", core.Concat("unsupported format: ", format), nil), OK: false}
|
2026-03-14 10:03:29 +00:00
|
|
|
}
|
|
|
|
|
}
|