- cmd/api: rewrite from Cobra CLI → Core command tree (c.Command) - cmd/api/cmd_spec.go: uses SpecBuilder.Build → core.Result - cmd/api/cmd_sdk.go: uses c.Process() for openapi-generator, core.Fs - bridge.go: string concat → core.Concat - graphql.go: string concat → core.Concat - openapi.go: string concat → core.Concat - proxy.go: strings → core.TrimPrefix/TrimSuffix, panic concat → core.Concat - Zero disallowed imports, zero string concat, zero old paths Co-Authored-By: Virgil <virgil@lethean.io>
47 lines
951 B
Go
47 lines
951 B
Go
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
package api
|
|
|
|
import (
|
|
core "dappco.re/go/core"
|
|
goapi "dappco.re/go/core/api"
|
|
)
|
|
|
|
func cmdSpec(c *core.Core) core.CommandAction {
|
|
return func(opts core.Options) core.Result {
|
|
format := opts.String("format")
|
|
if format == "" {
|
|
format = "json"
|
|
}
|
|
output := opts.String("output")
|
|
title := opts.String("title")
|
|
if title == "" {
|
|
title = "Lethean Core API"
|
|
}
|
|
ver := opts.String("version")
|
|
if ver == "" {
|
|
ver = "1.0.0"
|
|
}
|
|
|
|
builder := &goapi.SpecBuilder{
|
|
Title: title,
|
|
Description: "Lethean Core API",
|
|
Version: ver,
|
|
}
|
|
|
|
bridge := goapi.NewToolBridge("/tools")
|
|
groups := []goapi.RouteGroup{bridge}
|
|
|
|
if output != "" {
|
|
return goapi.ExportSpec(output, format, builder, groups)
|
|
}
|
|
|
|
// No output file — build and print to stdout
|
|
r := builder.Build(groups)
|
|
if !r.OK {
|
|
return r
|
|
}
|
|
core.Println(string(r.Value.([]byte)))
|
|
return core.Result{OK: true}
|
|
}
|
|
}
|