2022-06-20 19:31:28 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/invopop/jsonschema"
|
|
|
|
"go.balki.me/tss/app"
|
2022-06-21 22:17:16 -04:00
|
|
|
"gopkg.in/yaml.v3"
|
2022-06-20 19:31:28 -04:00
|
|
|
)
|
|
|
|
|
2022-06-21 22:17:16 -04:00
|
|
|
var refsDoc = `Placeholder to put any yaml anchors to use elsewhere, E.g.
|
|
|
|
refs:
|
|
|
|
myvpsproxy: &myvpsproxy "socks5://vps.example.com:1080"
|
|
|
|
twiceaday: &twiceaday "00 1,13 * * *"`
|
2022-06-20 19:31:28 -04:00
|
|
|
|
|
|
|
type config struct {
|
|
|
|
app.Config
|
|
|
|
|
|
|
|
Refs map[string]any `yaml:"refs" jsonschema:"refs"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
r := jsonschema.Reflector{
|
|
|
|
RequiredFromJSONSchemaTags: true,
|
|
|
|
DoNotReference: true,
|
|
|
|
ExpandedStruct: true,
|
|
|
|
}
|
2022-06-21 22:17:16 -04:00
|
|
|
err := r.AddGoComments("go.balki.me/tss", ".")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
r.CommentMap["main.config.Refs"] = refsDoc
|
|
|
|
|
|
|
|
s := r.Reflect(config{})
|
|
|
|
j, err := json.Marshal(s)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = os.WriteFile("./docs/schema.json", j, 0644)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var a any
|
|
|
|
err = yaml.Unmarshal(j, &a)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
y, err := yaml.Marshal(a)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = os.WriteFile("./docs/schema.yaml", y, 0644)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2022-06-20 19:31:28 -04:00
|
|
|
}
|