schema generator working
This commit is contained in:
parent
9bf1eeb379
commit
0c878468f5
@ -2,54 +2,60 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/invopop/jsonschema"
|
"github.com/invopop/jsonschema"
|
||||||
"go.balki.me/tss/app"
|
"go.balki.me/tss/app"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func fix(s string) string {
|
var refsDoc = `Placeholder to put any yaml anchors to use elsewhere, E.g.
|
||||||
// s := "go.balki.me/tss/home/balki/projects/tss/app.Config.Proxy"
|
refs:
|
||||||
return fmt.Sprintf("%s%s", s[:16], s[40:])
|
myvpsproxy: &myvpsproxy "socks5://vps.example.com:1080"
|
||||||
}
|
twiceaday: &twiceaday "00 1,13 * * *"`
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
app.Config
|
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"`
|
Refs map[string]any `yaml:"refs" jsonschema:"refs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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{
|
r := jsonschema.Reflector{
|
||||||
RequiredFromJSONSchemaTags: true,
|
RequiredFromJSONSchemaTags: true,
|
||||||
DoNotReference: true,
|
DoNotReference: true,
|
||||||
ExpandedStruct: true,
|
ExpandedStruct: true,
|
||||||
CommentMap: cmmap,
|
|
||||||
}
|
}
|
||||||
s := r.Reflect(c)
|
err := r.AddGoComments("go.balki.me/tss", ".")
|
||||||
j, _ := json.Marshal(s)
|
if err != nil {
|
||||||
os.WriteFile("/home/balki/projects/tss/docs/schema.json", j, 0644)
|
panic(err)
|
||||||
fmt.Println(string(j))
|
}
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
{"$schema":"http://json-schema.org/draft/2020-12/schema","properties":{"proxy":{"type":"string","description":"default proxy url that http.Client can understand\nor socks5://unix/path/to/sock for socks proxy over unix socket\nempty for no proxy","default":""},"telegram_proxy":{"type":"string","description":"proxy for telegram if different from default\nNONE to not use global default","default":"\u003cglobal proxy\u003e"},"telegram_auth_token":{"type":"string","description":"Auth token for telegram in the form of 424242424:AB02132skdcjlisjkjflewjlfkjslkfHHXX"},"data_dir":{"type":"string","description":"Base directory to write feed data and schedule file","default":"./"},"last_loaded_path":{"type":"string","description":"Path to the file where last success time for each feed is saved","default":"\u003cdatadir\u003e/last_success.yml"},"db_dir":{"type":"string","description":"Path to the directory where feed content is saved","default":"\u003cdatadir\u003e/feed_data"},"first_time_limit":{"type":"integer","description":"Number of entries to process when the feed is seen for the first time\n-1 means no limit","default":-1},"feeds":{"items":{"properties":{"name":{"type":"string","description":"Unique identifier for the feed. Used as filename, so keep it simple"},"channel":{"type":"string","description":"Telegram channel name in the form \"@foobar\" or \"-1004242442\" (private)"},"rhash":{"type":"string","description":"Telegram instant view rhash id, see https://instantview.telegram.org/#publishing-templates","default":""},"url":{"oneOf":[{"type":"string"},{"type":"array"}],"items":{"type":"string"},"description":"Feed Url, string or array of strings\nIf array, all entries are merged, e.g [\"https://example.com/blog/tag/foo/feed\", \"https://example.com/blog/tag/bar/feed\" ]"},"cron":{"type":"string","description":"Cron expression, see https://pkg.go.dev/github.com/robfig/cron#hdr-CRON_Expression_Format"},"proxy":{"type":"string","description":"Proxy for this feed if different from global","default":"\u003cglobal proxy\u003e"},"type":{"type":"string","enum":["rss","atom"],"description":"Rss or Atom feed"},"title":{"type":"string","description":"Text of the link sent to telegram,","default":"Link"},"first_time_limit":{"type":"integer","description":"Number of entries to process when the feed is seen for the first time","default":0}},"additionalProperties":false,"type":"object","required":["name","channel","url","cron","type"]},"type":"array","description":"Feed config"},"refs":{"type":"object"}},"additionalProperties":false,"type":"object","required":["telegram_auth_token","feeds"]}
|
{"$schema":"http://json-schema.org/draft/2020-12/schema","properties":{"proxy":{"type":"string","description":"default proxy url that http.Client can understand\nor socks5://unix/path/to/sock for socks proxy over unix socket\nempty for no proxy","default":""},"telegram_proxy":{"type":"string","description":"proxy for telegram if different from default\nNONE to not use global default","default":"\u003cglobal proxy\u003e"},"telegram_auth_token":{"type":"string","description":"Auth token for telegram in the form of 424242424:AB02132skdcjlisjkjflewjlfkjslkfHHXX"},"data_dir":{"type":"string","description":"Base directory to write feed data and schedule file","default":"./"},"last_loaded_path":{"type":"string","description":"Path to the file where last success time for each feed is saved","default":"\u003cdatadir\u003e/last_success.yml"},"db_dir":{"type":"string","description":"Path to the directory where feed content is saved","default":"\u003cdatadir\u003e/feed_data"},"first_time_limit":{"type":"integer","description":"Number of entries to process when the feed is seen for the first time\n-1 means no limit","default":-1},"feeds":{"items":{"properties":{"name":{"type":"string","description":"Unique identifier for the feed. Used as filename, so keep it simple"},"channel":{"type":"string","description":"Telegram channel name in the form \"@foobar\" or \"-1004242442\" (private)"},"rhash":{"type":"string","description":"Telegram instant view rhash id, see https://instantview.telegram.org/#publishing-templates","default":""},"url":{"oneOf":[{"type":"string"},{"type":"array"}],"items":{"type":"string"},"description":"Feed URL, string or array of strings\nIf array, all entries are merged, e.g [\"https://example.com/blog/tag/foo/feed\", \"https://example.com/blog/tag/bar/feed\" ]"},"cron":{"type":"string","description":"Cron expression, see https://pkg.go.dev/github.com/robfig/cron#hdr-CRON_Expression_Format"},"proxy":{"type":"string","description":"Proxy for this feed if different from global","default":"\u003cglobal proxy\u003e"},"type":{"type":"string","enum":["rss","atom"],"description":"Rss or Atom feed"},"title":{"type":"string","description":"Text of the link sent to telegram,","default":"Link"},"first_time_limit":{"type":"integer","description":"Number of entries to process when the feed is seen for the first time","default":0}},"additionalProperties":false,"type":"object","required":["name","channel","url","cron","type"]},"type":"array","description":"Feed config"},"refs":{"type":"object","description":"Placeholder to put any yaml anchors to use elsewhere, E.g.\nrefs:\n myvpsproxy: \u0026myvpsproxy \"socks5://vps.example.com:1080\"\n twiceaday: \u0026twiceaday \"00 1,13 * * *\""}},"additionalProperties":false,"type":"object","required":["telegram_auth_token","feeds"]}
|
133
docs/schema.yaml
133
docs/schema.yaml
@ -1,96 +1,101 @@
|
|||||||
$schema: http://json-schema.org/draft/2020-12/schema
|
$schema: http://json-schema.org/draft/2020-12/schema
|
||||||
|
additionalProperties: false
|
||||||
properties:
|
properties:
|
||||||
proxy:
|
|
||||||
type: string
|
|
||||||
description: |-
|
|
||||||
default proxy url that http.Client can understand
|
|
||||||
or socks5://unix/path/to/sock for socks proxy over unix socket
|
|
||||||
empty for no proxy
|
|
||||||
default: ""
|
|
||||||
telegram_proxy:
|
|
||||||
type: string
|
|
||||||
description: |-
|
|
||||||
proxy for telegram if different from default
|
|
||||||
NONE to not use global default
|
|
||||||
default: <global proxy>
|
|
||||||
telegram_auth_token:
|
|
||||||
type: string
|
|
||||||
description: Auth token for telegram in the form of 424242424:AB02132skdcjlisjkjflewjlfkjslkfHHXX
|
|
||||||
data_dir:
|
data_dir:
|
||||||
type: string
|
|
||||||
description: Base directory to write feed data and schedule file
|
|
||||||
default: ./
|
default: ./
|
||||||
last_loaded_path:
|
description: Base directory to write feed data and schedule file
|
||||||
type: string
|
type: string
|
||||||
description: Path to the file where last success time for each feed is saved
|
|
||||||
default: <datadir>/last_success.yml
|
|
||||||
db_dir:
|
db_dir:
|
||||||
type: string
|
|
||||||
description: Path to the directory where feed content is saved
|
|
||||||
default: <datadir>/feed_data
|
default: <datadir>/feed_data
|
||||||
first_time_limit:
|
description: Path to the directory where feed content is saved
|
||||||
type: integer
|
type: string
|
||||||
description: |-
|
|
||||||
Number of entries to process when the feed is seen for the first time
|
|
||||||
-1 means no limit
|
|
||||||
default: -1
|
|
||||||
feeds:
|
feeds:
|
||||||
|
description: Feed config
|
||||||
items:
|
items:
|
||||||
|
additionalProperties: false
|
||||||
properties:
|
properties:
|
||||||
name:
|
|
||||||
type: string
|
|
||||||
description: Unique identifier for the feed. Used as filename, so keep it simple
|
|
||||||
channel:
|
channel:
|
||||||
type: string
|
|
||||||
description: Telegram channel name in the form "@foobar" or "-1004242442" (private)
|
description: Telegram channel name in the form "@foobar" or "-1004242442" (private)
|
||||||
rhash:
|
|
||||||
type: string
|
type: string
|
||||||
description: Telegram instant view rhash id, see https://instantview.telegram.org/#publishing-templates
|
|
||||||
default: ""
|
|
||||||
url:
|
|
||||||
oneOf:
|
|
||||||
- type: string
|
|
||||||
- type: array
|
|
||||||
items:
|
|
||||||
type: string
|
|
||||||
description: |-
|
|
||||||
Feed Url, string or array of strings
|
|
||||||
If array, all entries are merged, e.g ["https://example.com/blog/tag/foo/feed", "https://example.com/blog/tag/bar/feed" ]
|
|
||||||
cron:
|
cron:
|
||||||
|
description: Cron expression, see https://pkg.go.dev/github.com/robfig/cron#hdr-CRON_Expression_Format
|
||||||
|
type: string
|
||||||
|
first_time_limit:
|
||||||
|
default: 0
|
||||||
|
description: Number of entries to process when the feed is seen for the first time
|
||||||
|
type: integer
|
||||||
|
name:
|
||||||
|
description: Unique identifier for the feed. Used as filename, so keep it simple
|
||||||
type: string
|
type: string
|
||||||
description: "Cron expression, see https://pkg.go.dev/github.com/robfig/cron#hdr-CRON_Expression_Format"
|
|
||||||
proxy:
|
proxy:
|
||||||
type: string
|
|
||||||
description: Proxy for this feed if different from global
|
|
||||||
default: <global proxy>
|
default: <global proxy>
|
||||||
type:
|
description: Proxy for this feed if different from global
|
||||||
type: string
|
type: string
|
||||||
|
rhash:
|
||||||
|
default: ""
|
||||||
|
description: Telegram instant view rhash id, see https://instantview.telegram.org/#publishing-templates
|
||||||
|
type: string
|
||||||
|
title:
|
||||||
|
default: Link
|
||||||
|
description: Text of the link sent to telegram,
|
||||||
|
type: string
|
||||||
|
type:
|
||||||
|
description: Rss or Atom feed
|
||||||
enum:
|
enum:
|
||||||
- rss
|
- rss
|
||||||
- atom
|
- atom
|
||||||
description: Rss or Atom feed
|
|
||||||
title:
|
|
||||||
type: string
|
type: string
|
||||||
description: Text of the link sent to telegram,
|
url:
|
||||||
default: Link
|
description: |-
|
||||||
first_time_limit:
|
Feed URL, string or array of strings
|
||||||
type: integer
|
If array, all entries are merged, e.g ["https://example.com/blog/tag/foo/feed", "https://example.com/blog/tag/bar/feed" ]
|
||||||
description: Number of entries to process when the feed is seen for the first time
|
items:
|
||||||
default: 0
|
type: string
|
||||||
additionalProperties: false
|
oneOf:
|
||||||
type: object
|
- type: string
|
||||||
|
- type: array
|
||||||
required:
|
required:
|
||||||
- name
|
- name
|
||||||
- channel
|
- channel
|
||||||
- url
|
- url
|
||||||
- cron
|
- cron
|
||||||
- type
|
- type
|
||||||
type: array
|
|
||||||
description: Feed config
|
|
||||||
refs:
|
|
||||||
type: object
|
type: object
|
||||||
additionalProperties: false
|
type: array
|
||||||
type: object
|
first_time_limit:
|
||||||
|
default: -1
|
||||||
|
description: |-
|
||||||
|
Number of entries to process when the feed is seen for the first time
|
||||||
|
-1 means no limit
|
||||||
|
type: integer
|
||||||
|
last_loaded_path:
|
||||||
|
default: <datadir>/last_success.yml
|
||||||
|
description: Path to the file where last success time for each feed is saved
|
||||||
|
type: string
|
||||||
|
proxy:
|
||||||
|
default: ""
|
||||||
|
description: |-
|
||||||
|
default proxy url that http.Client can understand
|
||||||
|
or socks5://unix/path/to/sock for socks proxy over unix socket
|
||||||
|
empty for no proxy
|
||||||
|
type: string
|
||||||
|
refs:
|
||||||
|
description: |-
|
||||||
|
Placeholder to put any yaml anchors to use elsewhere, E.g.
|
||||||
|
refs:
|
||||||
|
myvpsproxy: &myvpsproxy "socks5://vps.example.com:1080"
|
||||||
|
twiceaday: &twiceaday "00 1,13 * * *"
|
||||||
|
type: object
|
||||||
|
telegram_auth_token:
|
||||||
|
description: Auth token for telegram in the form of 424242424:AB02132skdcjlisjkjflewjlfkjslkfHHXX
|
||||||
|
type: string
|
||||||
|
telegram_proxy:
|
||||||
|
default: <global proxy>
|
||||||
|
description: |-
|
||||||
|
proxy for telegram if different from default
|
||||||
|
NONE to not use global default
|
||||||
|
type: string
|
||||||
required:
|
required:
|
||||||
- telegram_auth_token
|
- telegram_auth_token
|
||||||
- feeds
|
- feeds
|
||||||
|
type: object
|
||||||
|
Loading…
Reference in New Issue
Block a user