-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementa suporte a campos bool com default value #22
base: main
Are you sure you want to change the base?
Changes from all commits
8043ba6
f50e8b9
b50f506
33c84fa
c6cfb92
33769ae
6e9b131
0264d1c
dd9d817
bf2af67
1d15460
c60ef41
6288db8
60f3e5f
8f1f89e
b53eac8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
module "string" { | ||
source = "../string" | ||
count = try(var.manifest.items.type == "string", false) ? 1 : 0 | ||
|
||
metadata_name = var.metadata_name | ||
path = var.path | ||
field_path = "${var.field_path}.items" | ||
manifest = var.manifest.items | ||
} | ||
|
||
module "integer" { | ||
source = "../integer" | ||
count = try(var.manifest.items.type == "integer", false) ? 1 : 0 | ||
|
||
metadata_name = var.metadata_name | ||
path = var.path | ||
field_path = "${var.field_path}.items" | ||
manifest = var.manifest.items | ||
} | ||
|
||
module "bool" { | ||
source = "../bool" | ||
count = try(var.manifest.items.type == "bool", false) ? 1 : 0 | ||
|
||
metadata_name = var.metadata_name | ||
path = var.path | ||
field_path = "${var.field_path}.items" | ||
manifest = var.manifest.items | ||
} | ||
|
||
module "reduced_object" { | ||
source = "../reduced_object/" | ||
count = try(var.manifest.items.type == "object", false) ? 1 : 0 | ||
|
||
metadata_name = var.metadata_name | ||
path = var.path | ||
field_path = "${var.field_path}.items" | ||
manifest = var.manifest.items | ||
} | ||
|
||
output "schema" { | ||
value = { | ||
type = "array" | ||
version = "v0" | ||
subItem = one(flatten([ | ||
module.string[*].schema, module.integer[*].schema, | ||
module.bool[*].schema, module.reduced_object[*].schema, | ||
])) | ||
validations = { | ||
minItems = try(tonumber(var.manifest.minItems), null) | ||
maxItems = try(tonumber(var.manifest.maxItems), null) | ||
} | ||
} | ||
|
||
precondition { | ||
condition = can(var.manifest.items) | ||
error_message = <<-EOT | ||
Invalid "items" value. | ||
The field "${var.field_path}.items" are required. | ||
(metadata.name: "${var.metadata_name}", path: "${var.path}") | ||
EOT | ||
} | ||
|
||
precondition { | ||
condition = !can(var.manifest.items) || can(var.manifest.items.type) | ||
error_message = <<-EOT | ||
Invalid "items" value. | ||
The field "${var.field_path}.items.type" are required. | ||
(metadata.name: "${var.metadata_name}", path: "${var.path}") | ||
EOT | ||
} | ||
|
||
precondition { | ||
condition = !can(var.manifest.items) || !can(var.manifest.items.type) || try( | ||
contains(["string", "integer", "bool", "object"], var.manifest.items.type), | ||
true, | ||
) | ||
error_message = <<-EOT | ||
Invalid "items.type" value. | ||
The field "${var.field_path}.items.type" must be one of "string", "integer", "bool" or "object". | ||
(metadata.name: "${var.metadata_name}", path: "${var.path}") | ||
EOT | ||
} | ||
|
||
precondition { | ||
condition = can(var.manifest.items.type) | ||
error_message = <<-EOT | ||
Invalid "items" value. | ||
The field "${var.field_path}.items.type" are required. | ||
(metadata.name: "${var.metadata_name}", path: "${var.path}") | ||
EOT | ||
} | ||
|
||
precondition { | ||
condition = can(tonumber(try(var.manifest.minItems, null))) | ||
error_message = <<-EOT | ||
Invalid "minItems" value. | ||
The field "${var.field_path}.minItems" must be a number. | ||
(metadata.name: "${var.metadata_name}", path: "${var.path}") | ||
EOT | ||
} | ||
|
||
precondition { | ||
condition = try(tonumber(var.manifest.minItems) >= 0, true) | ||
error_message = <<-EOT | ||
Invalid "minItems" value. | ||
The field "${var.field_path}.minItems" must be greater than or equal to 0. | ||
(metadata.name: "${var.metadata_name}", path: "${var.path}") | ||
EOT | ||
} | ||
|
||
precondition { | ||
condition = can(tonumber(try(var.manifest.maxItems, null))) | ||
error_message = <<-EOT | ||
Invalid "maxItems" value. | ||
The field "${var.field_path}.maxItems" must be a number. | ||
(metadata.name: "${var.metadata_name}", path: "${var.path}") | ||
EOT | ||
} | ||
|
||
precondition { | ||
condition = try(tonumber(var.manifest.maxItems) >= 1, true) | ||
error_message = <<-EOT | ||
Invalid "maxItems" value. | ||
The field "${var.field_path}.maxItems" must be greater than or equal to 1. | ||
(metadata.name: "${var.metadata_name}", path: "${var.path}") | ||
EOT | ||
} | ||
|
||
precondition { | ||
condition = try(var.manifest.minItems < var.manifest.maxItems, true) | ||
error_message = <<-EOT | ||
Invalid "minItems" and "maxItems" values. | ||
The field "${var.field_path}.minItems" must be less than "${var.field_path}.maxItems". | ||
(metadata.name: "${var.metadata_name}", path: "${var.path}") | ||
EOT | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
variable "metadata_name" { | ||
type = string | ||
} | ||
|
||
variable "path" { | ||
type = string | ||
} | ||
|
||
variable "field_path" { | ||
type = string | ||
} | ||
|
||
variable "manifest" { | ||
type = any | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
locals { | ||
declared_default_field = contains(keys(var.manifest), "default") | ||
} | ||
|
||
output "schema" { | ||
value = { | ||
type = "bool" | ||
version = "v1" | ||
subItem = null | ||
validations = { | ||
has_default_value = can(var.manifest.default) ? true : false | ||
default_value = try(var.manifest.default, null) | ||
} | ||
} | ||
|
||
precondition { | ||
condition = !( | ||
local.declared_default_field && try(var.manifest.default, null) == null | ||
) | ||
Comment on lines
+18
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aqui não deveria ser |
||
error_message = <<-EOT | ||
Invalid Manifest! | ||
O valor default de um campo bool não pode ser null; | ||
O campo ${var.field_path} tem seu default value definido como null. | ||
(metadata: ${var.metadata_name}; path: ${var.path}; ) | ||
Comment on lines
+22
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A mensagem está boa, mas para seguir o padrão do projeto ela precisa ser em inglês |
||
EOT | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
variable "metadata_name" { | ||
type = string | ||
} | ||
|
||
variable "path" { | ||
type = string | ||
} | ||
|
||
variable "field_path" { | ||
type = string | ||
} | ||
|
||
variable "manifest" { | ||
type = any | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
output "schema" { | ||
value = { | ||
type = "integer" | ||
version = "v0" | ||
subItem = null | ||
validations = { | ||
minimum = try(tonumber(var.manifest.minimum), null) | ||
maximum = try(tonumber(var.manifest.maximum), null) | ||
} | ||
} | ||
|
||
precondition { | ||
condition = can(tonumber(try(var.manifest.minimum, null))) | ||
error_message = <<-EOT | ||
Invalid "minimum" value. | ||
The field "${var.field_path}.minimum" must be a number. | ||
(metadata.name: "${var.metadata_name}", path: "${var.path}") | ||
EOT | ||
} | ||
|
||
precondition { | ||
condition = can(tonumber(try(var.manifest.maximum, null))) | ||
error_message = <<-EOT | ||
Invalid "maximum" value. | ||
The field "${var.field_path}.maximum" must be a number. | ||
(metadata.name: "${var.metadata_name}", path: "${var.path}") | ||
EOT | ||
} | ||
|
||
precondition { | ||
condition = try(var.manifest.minimum < var.manifest.maximum, true) | ||
error_message = <<-EOT | ||
Invalid "minimum" and "maximum" values. | ||
The field "${var.field_path}.minimum" must be less than "${var.field_path}.maximum". | ||
(metadata.name: "${var.metadata_name}", path: "${var.path}") | ||
EOT | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
variable "metadata_name" { | ||
type = string | ||
} | ||
|
||
variable "path" { | ||
type = string | ||
} | ||
|
||
variable "field_path" { | ||
type = string | ||
} | ||
|
||
variable "manifest" { | ||
type = any | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module "version" { | ||
source = "./version" | ||
count = try(length(var.manifest.spec.versions), 0) | ||
|
||
metadata_name = var.manifest.metadata.name | ||
path = var.path | ||
field_path = "spec.versions[${count.index}]" | ||
manifest = try(var.manifest.spec.versions[count.index], null) | ||
} | ||
|
||
output "schema" { | ||
value = { | ||
path = var.path | ||
name = var.manifest.metadata.name | ||
group = try(var.manifest.spec.group, null) | ||
kind = try(var.manifest.spec.kind, null) | ||
versions = { for _, value in module.version : value.schema.name => value.schema } | ||
} | ||
|
||
precondition { | ||
condition = can(var.manifest.spec.group) | ||
error_message = <<-EOT | ||
Invalid manifest. | ||
The "spec.group" field is required. | ||
(metadata.name: "${var.manifest.metadata.name}", path: "${var.path}") | ||
EOT | ||
} | ||
|
||
precondition { | ||
condition = can(var.manifest.spec.kind) | ||
error_message = <<-EOT | ||
Invalid manifest. | ||
The "spec.kind" field is required. | ||
(metadata.name: "${var.manifest.metadata.name}", path: "${var.path}") | ||
EOT | ||
} | ||
|
||
precondition { | ||
condition = can(var.manifest.spec.versions) | ||
error_message = <<-EOT | ||
Invalid manifest. | ||
The "spec.versions" field is required. | ||
(metadata.name: "${var.manifest.metadata.name}", path: "${var.path}") | ||
EOT | ||
} | ||
|
||
precondition { | ||
condition = !can(var.manifest.spec.versions) || can(length(var.manifest.spec.versions)) | ||
error_message = <<-EOT | ||
Invalid manifest. | ||
The "spec.versions" field must be an array. | ||
(metadata.name: "${var.manifest.metadata.name}", path: "${var.path}") | ||
EOT | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O schema deveria carregar o campo já em seu valor final. Com isso em mente, a validação se o campo default possui um valor válido, deveria estar aqui.