56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/invopop/jsonschema"
|
|
"go.balki.me/tss/app"
|
|
)
|
|
|
|
func fix(s string) string {
|
|
// s := "go.balki.me/tss/home/balki/projects/tss/app.Config.Proxy"
|
|
return fmt.Sprintf("%s%s", s[:16], s[40:])
|
|
}
|
|
|
|
type config struct {
|
|
app.Config
|
|
|
|
// Placeholder to put any yaml anchors to use elsewhere, E.g.
|
|
// refs:
|
|
// myvpsproxy: &myvpsproxy "socks5://vps.example.com:1080"
|
|
// twiceaday: &twiceaday "00 1,13 * * *"
|
|
Refs map[string]any `yaml:"refs" jsonschema:"refs"`
|
|
}
|
|
|
|
func main() {
|
|
// "go.balki.me/tss/app.FeedCfg.Channel": "Telegram channel name in the form \"@foobar\" or \"-1004242442\"",
|
|
//s go.balki.me/tss/app.FeedCfg.Channel
|
|
// foo()
|
|
// return
|
|
fmt.Println("vim-go")
|
|
cmmap := map[string]string{}
|
|
err := jsonschema.ExtractGoComments("go.balki.me/tss", "/home/balki/projects/tss", cmmap)
|
|
cmmapF := map[string]string{}
|
|
for k, v := range cmmap {
|
|
cmmapF[fix(k)] = v
|
|
}
|
|
cmmap = cmmapF
|
|
fmt.Println("err", err)
|
|
d, err := json.Marshal(cmmap)
|
|
fmt.Printf("%s\n", string(d))
|
|
os.WriteFile("/tmp/cmmap.json", d, 0644)
|
|
var c config
|
|
r := jsonschema.Reflector{
|
|
RequiredFromJSONSchemaTags: true,
|
|
DoNotReference: true,
|
|
ExpandedStruct: true,
|
|
CommentMap: cmmap,
|
|
}
|
|
s := r.Reflect(c)
|
|
j, _ := json.Marshal(s)
|
|
os.WriteFile("/home/balki/projects/tss/docs/schema.json", j, 0644)
|
|
fmt.Println(string(j))
|
|
}
|