-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate JSON Schema for External Validation #363
Comments
I'd like to throw my vote behind this feature also, but for slightly different outcomes. A machine-readable schema of all specifications in https://coreos.github.io/butane/specs/ will allow me to use my IDE to tell me what I can and can't write, as well as what I must write, instead of me as a human continually referencing the documentation with my fallible eyes and fallible brain. The existing documentation is fantastic for purpose and semantic intent, but machine-readable documentation would be fantastic for speeding up my development — That is, preventing me entirely from writing something invalid, rather than finding out at ignition generation time. For other readers, in the interim I am generating the schema I need myself, using package main
import (
"encoding/json"
"fmt"
"os"
"github.com/coreos/butane/config/fcos/v1_4"
"github.com/invopop/jsonschema"
)
func main() {
s := jsonschema.Reflect(v1_4.Config{})
data, err := json.MarshalIndent(s, "", " ")
if err != nil {
panic(err.Error())
}
file, err := os.OpenFile("fcos.v1_4.schema.json", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
panic(err.Error())
}
defer file.Close()
_, err = fmt.Fprintf(file, string(data))
if err != nil {
panic(err.Error())
}
} Note that this isn't quite the same, as default struct values in Golang are doing a lot of heavy lifting. For example, using |
Could schema generation be added to internal/doc/main.go so this can be automated? On first glance it doesn't look to be too much work when using invopop/jsonschema as @jbirch-atlassian suggested. |
I would like to take this file https://github.com/coreos/butane/blob/main/config/flatcar/v1_1_exp/schema.go and generate a JSON schema for validating generated Ignition configs,
The text was updated successfully, but these errors were encountered: