Skip to content

Commit

Permalink
Refactor jsonschema generator and add omit setting
Browse files Browse the repository at this point in the history
  • Loading branch information
karimkhaleel committed Oct 1, 2023
1 parent 4db36c3 commit 36dc3cd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/jsonschema/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ func GenerateSchema() {
schema := customReflect(&config.UserConfig{})
obj, _ := json.MarshalIndent(schema, "", " ")

if err := os.WriteFile(GetSchemaDir()+"/schema.json", obj, 0o644); err != nil {
if err := os.WriteFile(GetSchemaDir()+"/config.json", obj, 0o644); err != nil {
fmt.Println("Error writing to file:", err)
return
}
}

func customReflect(v *config.UserConfig) *jsonschema.Schema {
defaultConfig := config.GetDefaultConfig()
r := &jsonschema.Reflector{KeyNamer: func(name string) string { return name }, FieldNameTag: "yaml"}
if err := r.AddGoComments("github.com/jesseduffield/lazygit", "./"); err != nil {
r := &jsonschema.Reflector{FieldNameTag: "yaml", RequiredFromJSONSchemaTags: true}
if err := r.AddGoComments("github.com/jesseduffield/lazygit/pkg/config", "../config"); err != nil {
panic(err)
}
schema := r.Reflect(v)
Expand Down Expand Up @@ -60,7 +60,7 @@ func setDefaultVals(defaults interface{}, schema *jsonschema.Schema) {

isNil := true
switch value.Kind() {
case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.Interface, reflect.Slice:
case reflect.Map, reflect.Ptr, reflect.Interface, reflect.Slice:
isNil = value.IsNil()
default:
}
Expand Down

0 comments on commit 36dc3cd

Please sign in to comment.