Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/jsonschema/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func fromString(s string, T Type) (any, error) {
case BooleanType:
v, err = strconv.ParseBool(s)
case NumberType:
v, err = strconv.ParseFloat(s, 32)
v, err = strconv.ParseFloat(s, 64)
case IntegerType:
v, err = strconv.ParseInt(s, 10, 64)
case ArrayType, ObjectType:
Expand Down
5 changes: 2 additions & 3 deletions libs/jsonschema/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,15 @@

v, err = fromString("1.1", NumberType)
assert.NoError(t, err)
// Floating point conversions are not perfect
assert.Less(t, (v.(float64) - 1.1), 0.000001)
assert.Equal(t, 1.1, v)

Check failure on line 98 in libs/jsonschema/utils_test.go

View workflow job for this annotation

GitHub Actions / lint

float-compare: use assert.InEpsilon (or InDelta) (testifylint)

v, err = fromString("12345", IntegerType)
assert.NoError(t, err)
assert.Equal(t, int64(12345), v)

v, err = fromString("123", NumberType)
assert.NoError(t, err)
assert.InDelta(t, float64(123), v.(float64), 0.0001)
assert.Equal(t, float64(123), v)

Check failure on line 106 in libs/jsonschema/utils_test.go

View workflow job for this annotation

GitHub Actions / lint

float-compare: use assert.InEpsilon (or InDelta) (testifylint)

_, err = fromString("qrt", ArrayType)
assert.EqualError(t, err, "cannot parse string as object of type array. Value of string: \"qrt\"")
Expand Down
Loading