Skip to content

Commit

Permalink
nesting default values inline (#13)
Browse files Browse the repository at this point in the history
* nesting default values inline

* mostly working, need to fix 'nil' on missing values in default object

* small tweaks

* fixed bug with default object

* updated tests to include more test cases
* fixed bug where default object was being assumed to have values that
only exist within in-line field declarations

* Renaming def to defaults

* Reordering inputs to match other hydrate helper functions

* add comment for removenullkeys

---------

Co-authored-by: chrisghill <[email protected]>
  • Loading branch information
mclacore and chrisghill authored Oct 3, 2024
1 parent 0efbcc7 commit 47f89a8
Show file tree
Hide file tree
Showing 4 changed files with 344 additions and 140 deletions.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var rootCmd = &cobra.Command{
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
rootCmd.AddCommand(NewCmdBicep())
rootCmd.AddCommand(NewCmdHelm())
rootCmd.AddCommand(NewCmdOpenTofu())
rootCmd.AddCommand(NewCmdValidate())
Expand Down
295 changes: 200 additions & 95 deletions pkg/opentofu/testdata/opentofu/simple/schema.json
Original file line number Diff line number Diff line change
@@ -1,97 +1,202 @@
{
"required": [
"nodescription",
"testbool",
"testemptybool",
"testlist",
"testmap",
"testnumber",
"testobject",
"testset",
"teststring"
],
"properties": {
"teststring": {
"title": "teststring",
"type": "string",
"description": "An example string variable",
"default": "string value"
},
"testnumber": {
"title": "testnumber",
"type": "number",
"description": "An example number variable",
"default": 20
},
"testbool": {
"title": "testbool",
"type": "boolean",
"description": "An example bool variable",
"default": false
},
"testemptybool": {
"title": "testemptybool",
"type": "boolean",
"description": "An example empty bool variable",
"default": false
},
"testobject": {
"title": "testobject",
"type": "object",
"properties": {
"name": {
"title": "name",
"type": "string"
},
"address": {
"title": "address",
"type": "string"
},
"age": {
"title": "age",
"type": "number"
}
},
"required": [
"name"
],
"description": "An example object variable",
"default": {
"name": "Bob",
"address": "123 Bob St."
}
},
"testlist": {
"title": "testlist",
"type": "array",
"description": "An example list variable",
"items": {
"type": "string"
}
},
"testset": {
"title": "testset",
"type": "array",
"uniqueItems": true,
"description": "An example set variable",
"items": {
"type": "string"
}
},
"testmap": {
"title": "testmap",
"type": "object",
"description": "An example map variable",
"propertyNames": {
"pattern": "^.*$"
},
"additionalProperties": {
"type": "string"
}
},
"nodescription": {
"title": "nodescription",
"type": "string"
}
}
"required": [
"nodescription",
"testbool",
"testemptybool",
"testlist",
"testmap",
"testnestedobject",
"testnumber",
"testobject",
"testset",
"teststring"
],
"properties": {
"teststring": {
"title": "teststring",
"type": "string",
"description": "An example string variable",
"default": "string value"
},
"testnumber": {
"title": "testnumber",
"type": "number",
"description": "An example number variable",
"default": 20
},
"testbool": {
"title": "testbool",
"type": "boolean",
"description": "An example bool variable",
"default": false
},
"testemptybool": {
"title": "testemptybool",
"type": "boolean",
"description": "An example empty bool variable",
"default": false
},
"testobject": {
"title": "testobject",
"type": "object",
"properties": {
"name": {
"title": "name",
"type": "string"
},
"address": {
"title": "address",
"type": "string"
},
"age": {
"title": "age",
"type": "number"
}
},
"required": [
"name"
],
"description": "An example object variable",
"default": {
"name": "Bob",
"address": "123 Bob St."
}
},
"testnestedobject": {
"title": "testnestedobject",
"description": "An example nested object variable",
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"title": "name",
"type": "string"
},
"address": {
"title": "address",
"type": "string",
"default": "123 Bob St."
},
"age": {
"title": "age",
"type": "number",
"default": 30
},
"dead": {
"title": "dead",
"type": "boolean",
"default": false
},
"phones": {
"title": "phones",
"type": "object",
"default": {
"home": "987-654-3210"
},
"required": [
"home"
],
"properties": {
"home": {
"title": "home",
"type": "string"
},
"work": {
"title": "work",
"type": "string",
"default": "123-456-7891"
}
}
},
"children": {
"title": "children",
"type": "array",
"default": [
{
"name": "bob",
"occupation": {
"company": "none",
"experience": 2,
"manager": true
}
}
],
"items": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"title": "name",
"type": "string"
},
"occupation": {
"title": "occupation",
"type": "object",
"default": {
"company": "Massdriver",
"experience": 1,
"manager": false
},
"required": [
"company"
],
"properties": {
"company": {
"title": "company",
"type": "string"
},
"experience": {
"title": "experience",
"type": "number",
"default": 0
},
"manager": {
"title": "manager",
"type": "boolean",
"default": false
}
}
}
}
}
}
}
},
"testlist": {
"title": "testlist",
"type": "array",
"description": "An example list variable",
"items": {
"type": "string"
}
},
"testset": {
"title": "testset",
"type": "array",
"uniqueItems": true,
"description": "An example set variable",
"items": {
"type": "string"
}
},
"testmap": {
"title": "testmap",
"type": "object",
"description": "An example map variable",
"propertyNames": {
"pattern": "^.*$"
},
"additionalProperties": {
"type": "string"
}
},
"nodescription": {
"title": "nodescription",
"type": "string"
}
}
}
Loading

0 comments on commit 47f89a8

Please sign in to comment.