Skip to content

Commit

Permalink
fix: better comment and id
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox committed Jan 9, 2025
1 parent 9ff4bf2 commit 2a04391
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 6 additions & 4 deletions internal/gen/jsonschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"reflect"
"time"

"github.com/invopop/jsonschema"

Expand All @@ -14,7 +15,6 @@ import (
func main() {
r := new(jsonschema.Reflector)
r.ExpandedStruct = true
r.AllowAdditionalProperties = true
r.AdditionalFields = func(t reflect.Type) []reflect.StructField {
if t == reflect.TypeOf(config.Config{}) {
return reflect.VisibleFields(reflect.TypeOf(struct {
Expand Down Expand Up @@ -51,12 +51,14 @@ func main() {

return []reflect.StructField{}
}

schema, err := json.MarshalIndent(r.Reflect(&config.Config{}), "", " ")
schema := r.Reflect(&config.Config{})
schema.ID = "https://json.schemastore.org/lefthook.json"
schema.Comments = "Last updated on " + time.Now().Format("2006.01.02") + "."
dumped, err := json.MarshalIndent(schema, "", " ")
if err != nil {
log.Error(err)
return
}

log.Info(string(schema))
log.Info(string(dumped))
}
10 changes: 9 additions & 1 deletion schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/evilmartians/lefthook/internal/config/config",
"$id": "https://json.schemastore.org/lefthook.json",
"$defs": {
"Command": {
"properties": {
Expand Down Expand Up @@ -80,6 +80,7 @@
"type": "boolean"
}
},
"additionalProperties": false,
"type": "object",
"required": [
"run"
Expand All @@ -103,6 +104,7 @@
"type": "array"
}
},
"additionalProperties": false,
"type": "object",
"required": [
"jobs"
Expand Down Expand Up @@ -167,6 +169,7 @@
"type": "object"
}
},
"additionalProperties": false,
"type": "object"
},
"Job": {
Expand Down Expand Up @@ -276,6 +279,7 @@
"$ref": "#/$defs/Group"
}
},
"additionalProperties": false,
"type": "object"
},
"Remote": {
Expand Down Expand Up @@ -314,6 +318,7 @@
"description": "Deprecated: use configs"
}
},
"additionalProperties": false,
"type": "object"
},
"Script": {
Expand Down Expand Up @@ -369,9 +374,11 @@
"type": "boolean"
}
},
"additionalProperties": false,
"type": "object"
}
},
"$comment": "Last updated on 2025.01.09.",
"properties": {
"min_version": {
"type": "string",
Expand Down Expand Up @@ -537,5 +544,6 @@
"$ref": "#/$defs/Hook"
}
},
"additionalProperties": false,
"type": "object"
}

0 comments on commit 2a04391

Please sign in to comment.