Skip to content

Commit

Permalink
bugfix: skip validating the float number in the body (#469)
Browse files Browse the repository at this point in the history
* bugfix: skip validating the float number in the body

* update comments

* fix goimports

* fix tests
  • Loading branch information
ms-henglu committed Apr 25, 2024
1 parent 3afdfe2 commit dcdb423
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ BUG FIXES:
- Fix a bug when upgrading from previous provider `azapi_resource` resource will set `tags` for resources that don't have `tags` in the configuration.
- Fix a bug that `azapi_resource` resource cannot handle tags with unknown values.
- Fix a bug that `null` value can't pass the schema validation.
- Fix a bug that schema validation fails to validate the float number in the body.

## v1.13.0
BREAKING CHANGES:
Expand Down
15 changes: 4 additions & 11 deletions internal/azure/types/integer_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package types

import (
"fmt"
"math"

"github.com/Azure/terraform-provider-azapi/internal/azure/utils"
)
Expand All @@ -26,16 +25,10 @@ func (t *IntegerType) Validate(body interface{}, path string) []error {
}
var v int
switch input := body.(type) {
case float64:
if math.Round(input) != input {
return []error{utils.ErrorMismatch(path, "integer", fmt.Sprintf("%T", body))}
}
v = int(input)
case float32:
if math.Round(float64(input)) != float64(input) {
return []error{utils.ErrorMismatch(path, "integer", fmt.Sprintf("%T", body))}
}
v = int(input)
case float64, float32:
// TODO: skip validation for now because of the following issue:
// the bicep-types-az parses float as integer type and it should be fixed: https://github.com/Azure/bicep-types-az/issues/1404
return nil
case int64:
v = int(input)
case int32:
Expand Down
5 changes: 4 additions & 1 deletion internal/azure/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ func Test_BodyValidation(t *testing.T) {
}
}
`,
Error: true,
// TODO: change the error to true once the validation is enabled
// the validation is disabled for now, because of the following issue:
// the bicep-types-az parses float as integer type and it should be fixed: https://github.com/Azure/bicep-types-az/issues/1404
Error: false,
},
}

Expand Down

0 comments on commit dcdb423

Please sign in to comment.