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
|
|
|
"sync"
|
|
|
|
|
"sync/atomic"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
swaggerFiles "github.com/swaggo/files"
|
|
|
|
|
ginSwagger "github.com/swaggo/gin-swagger"
|
|
|
|
|
"github.com/swaggo/swag"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// swaggerSeq provides unique instance names so multiple Engine instances
|
|
|
|
|
// (common in tests) do not collide in the global swag registry.
|
|
|
|
|
var swaggerSeq atomic.Uint64
|
|
|
|
|
|
|
|
|
|
// swaggerSpec wraps SpecBuilder to satisfy the swag.Spec interface.
|
|
|
|
|
// The spec is built once on first access and cached.
|
|
|
|
|
type swaggerSpec struct {
|
|
|
|
|
builder *SpecBuilder
|
|
|
|
|
groups []RouteGroup
|
|
|
|
|
once sync.Once
|
|
|
|
|
doc string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ReadDoc returns the OpenAPI 3.1 JSON document for this spec.
|
|
|
|
|
func (s *swaggerSpec) ReadDoc() string {
|
|
|
|
|
s.once.Do(func() {
|
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
|
|
|
r := s.builder.Build(s.groups)
|
|
|
|
|
if !r.OK {
|
2026-03-14 10:03:29 +00:00
|
|
|
s.doc = `{"openapi":"3.1.0","info":{"title":"error","version":"0.0.0"},"paths":{}}`
|
|
|
|
|
return
|
|
|
|
|
}
|
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
|
|
|
s.doc = string(r.Value.([]byte))
|
2026-03-14 10:03:29 +00:00
|
|
|
})
|
|
|
|
|
return s.doc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// registerSwagger mounts the Swagger UI and doc.json endpoint.
|
|
|
|
|
func registerSwagger(g *gin.Engine, title, description, version string, groups []RouteGroup) {
|
|
|
|
|
spec := &swaggerSpec{
|
|
|
|
|
builder: &SpecBuilder{
|
|
|
|
|
Title: title,
|
|
|
|
|
Description: description,
|
|
|
|
|
Version: version,
|
|
|
|
|
},
|
|
|
|
|
groups: groups,
|
|
|
|
|
}
|
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
|
|
|
name := core.Sprintf("swagger_%d", swaggerSeq.Add(1))
|
2026-03-14 10:03:29 +00:00
|
|
|
swag.Register(name, spec)
|
|
|
|
|
g.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.NewHandler(), ginSwagger.InstanceName(name)))
|
|
|
|
|
}
|