Skip to content

Commit

Permalink
link to JSON schema for (*Argument.Schema)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredallard committed Jun 6, 2024
1 parent 38bc0ad commit a464b51
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ type Argument struct {
Default interface{} `yaml:"default,omitempty"`

// Schema is a JSON schema, in YAML, for the argument.
Schema map[string]interface{} `yaml:"schema"`
Schema map[string]any `yaml:"schema"`

// From is a reference to an argument in another module, if this is
// set, all other fields are ignored and instead the module referenced
Expand Down
2 changes: 1 addition & 1 deletion schemas/manifest.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"description": "Default is the default value for this argument if it's not set.\nThis cannot be set when required is true."
},
"schema": {
"type": "object",
"$ref": "https://json-schema.org/draft-07/schema#",
"description": "Schema is a JSON schema, in YAML, for the argument."
},
"from": {
Expand Down
2 changes: 1 addition & 1 deletion schemas/stencil.jsonschema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "https://json-schema.org/draft-07/schema#",
"$id": "https://go.rgst.io/stencil/pkg/configuration/manifest",
"$ref": "#/$defs/Manifest",
"$defs": {
Expand Down
12 changes: 12 additions & 0 deletions tools/schemagen/schemagen.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ func main() {
// VSCode doesn't handle above draft-07 right now, so we force it.
schema.Version = "https://json-schema.org/draft-07/schema#"

// Apply manifest-specific overrides.
if s.FileName == "manifest" {
subSchema, ok := schema.Definitions["Argument"].Properties.Get("schema")
if !ok {
fmt.Println("failed to update schema property for manifest to include $ref")
os.Exit(1)
}

subSchema.Ref = schema.Version
subSchema.Type = "" // Don't set type.
}

b, err := schema.MarshalJSON()
if err != nil {
fmt.Printf("error generating schema for %s: %v\n", s.FileName, err)
Expand Down

0 comments on commit a464b51

Please sign in to comment.