package main
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"github.com/invopop/jsonschema"
"github.com/pancsta/asyncmachine-go/pkg/integrations"
)
func main() {
r := new (jsonschema .Reflector )
if err := r .AddGoComments ("github.com/pancsta/asyncmachine-go" ,
"./pkg/integrations" ); err != nil {
panic (err )
}
schemaDir := filepath .Join ("docs" , "jsonschema" )
if err := os .MkdirAll (schemaDir , 0755 ); err != nil {
panic (err )
}
structs := []struct {
name string
obj interface {}
}{
{"msg_kind_req" , &integrations .MsgKindReq {}},
{"msg_kind_resp" , &integrations .MsgKindResp {}},
{"mutation_req" , &integrations .MutationReq {}},
{"mutation_resp" , &integrations .MutationResp {}},
{"waiting_req" , &integrations .WaitingReq {}},
{"waiting_resp" , &integrations .WaitingResp {}},
{"getter_req" , &integrations .GetterReq {}},
{"getter_resp" , &integrations .GetterResp {}},
}
for _ , s := range structs {
schema := r .Reflect (s .obj )
jsonData , err := json .MarshalIndent (schema , "" , " " )
if err != nil {
panic (fmt .Errorf ("failed to marshal schema for %s: %v" , s .name , err ))
}
filename := filepath .Join (schemaDir , s .name +".json" )
if err := os .WriteFile (filename , jsonData , 0644 ); err != nil {
panic (fmt .Errorf ("failed to write schema for %s: %v" , s .name , err ))
}
fmt .Printf ("Generated /%s\n" , filename )
}
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .