From ce264f1fcae910ae4a8d4a4073687cf30f95e620 Mon Sep 17 00:00:00 2001 From: Carlos A Becker Date: Wed, 17 Aug 2022 23:50:14 -0300 Subject: [PATCH] fix: jsonschema very hacky, fixes #3238 for good refs https://github.com/invopop/jsonschema/issues/26 Signed-off-by: Carlos A Becker --- cmd/schema.go | 1 + pkg/config/config.go | 6 ++---- www/docs/static/schema.json | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/cmd/schema.go b/cmd/schema.go index c720fe453a7..d3a4853d3b0 100644 --- a/cmd/schema.go +++ b/cmd/schema.go @@ -27,6 +27,7 @@ func newSchemaCmd() *schemaCmd { Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { schema := jsonschema.Reflect(&config.Project{}) + schema.Definitions["FileInfo"] = jsonschema.Reflect(&config.FileInfo{}) schema.Description = "goreleaser configuration definition file" bts, err := json.MarshalIndent(schema, " ", " ") if err != nil { diff --git a/pkg/config/config.go b/pkg/config/config.go index 22242a7b9ae..acf1c8dc9e2 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -427,18 +427,16 @@ type FileInfo struct { MTime time.Time `yaml:"mtime,omitempty" json:"mtime,omitempty"` } -// type alias to prevent stack overflow -type fileAlias File - // UnmarshalYAML is a custom unmarshaler that wraps strings in arrays. func (f *File) UnmarshalYAML(unmarshal func(interface{}) error) error { + type t File var str string if err := unmarshal(&str); err == nil { *f = File{Source: str} return nil } - var file fileAlias + var file t if err := unmarshal(&file); err != nil { return err } diff --git a/www/docs/static/schema.json b/www/docs/static/schema.json index 6242611bde8..c01e6bfde34 100644 --- a/www/docs/static/schema.json +++ b/www/docs/static/schema.json @@ -731,6 +731,32 @@ } ] }, + "FileInfo": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/goreleaser/goreleaser/pkg/config/file-info", + "$ref": "#/$defs/FileInfo", + "$defs": { + "FileInfo": { + "properties": { + "owner": { + "type": "string" + }, + "group": { + "type": "string" + }, + "mode": { + "type": "integer" + }, + "mtime": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object" + } + } + }, "Filters": { "properties": { "exclude": {