diff --git a/providers/openapi/schema/parse_xml.go b/providers/openapi/schema/parse_xml.go index c8cfd555d..1ce49fc85 100644 --- a/providers/openapi/schema/parse_xml.go +++ b/providers/openapi/schema/parse_xml.go @@ -167,11 +167,11 @@ func parseValue(s string, ref *Schema) (interface{}, error) { t := ref.Type if t.IsInteger() { - v, err := strconv.Atoi(s) + val64, err := strconv.ParseInt(s, 10, 32) if err != nil { return nil, fmt.Errorf("parse integer failed: %v", s) } - return v, nil + return val64, nil } if t.IsNumber() { diff --git a/providers/openapi/schema/parse_xml_test.go b/providers/openapi/schema/parse_xml_test.go index b1873820c..a87f14994 100644 --- a/providers/openapi/schema/parse_xml_test.go +++ b/providers/openapi/schema/parse_xml_test.go @@ -161,7 +161,7 @@ func TestUnmarshalXML(t *testing.T) { test: func(t *testing.T) { v, err := schema.UnmarshalXML(strings.NewReader("2005"), schematest.New("integer")) require.NoError(t, err) - require.Equal(t, 2005, v) + require.Equal(t, int64(2005), v) }, }, { @@ -229,7 +229,7 @@ func TestUnmarshalXML(t *testing.T) { ), )) require.NoError(t, err) - require.Equal(t, map[string]interface{}{"foo": 123, "yuh": "bar"}, v) + require.Equal(t, map[string]interface{}{"foo": int64(123), "yuh": "bar"}, v) }, }, { @@ -338,7 +338,7 @@ func TestUnmarshalXML(t *testing.T) { ), ) require.NoError(t, err) - require.Equal(t, map[string]interface{}{"id": 15, "author": "J K. Rowling", "title": "Harry Potter", "smp": "https://example.com/schema"}, v) + require.Equal(t, map[string]interface{}{"id": int64(15), "author": "J K. Rowling", "title": "Harry Potter", "smp": "https://example.com/schema"}, v) }, }, { @@ -413,7 +413,7 @@ func TestUnmarshalXML_Old(t *testing.T) { schematest.WithProperty("author", schematest.New("string"))), test: func(t *testing.T, i interface{}, err error) { require.NoError(t, err) - require.Equal(t, map[string]interface{}{"id": 0, "title": "foo", "author": "bar"}, i) + require.Equal(t, map[string]interface{}{"id": int64(0), "title": "foo", "author": "bar"}, i) }, }, { @@ -426,7 +426,7 @@ func TestUnmarshalXML_Old(t *testing.T) { schematest.WithProperty("author", schematest.New("string", schematest.WithXml(&schema.Xml{Name: "Author"})))), test: func(t *testing.T, i interface{}, err error) { require.NoError(t, err) - require.Equal(t, map[string]interface{}{"id": 0, "title": "foo", "author": "bar"}, i) + require.Equal(t, map[string]interface{}{"id": int64(0), "title": "foo", "author": "bar"}, i) }, }, } diff --git a/schema/json/parser/parser_integer.go b/schema/json/parser/parser_integer.go index ee2a8a229..42fc17e2b 100644 --- a/schema/json/parser/parser_integer.go +++ b/schema/json/parser/parser_integer.go @@ -38,14 +38,14 @@ func (p *Parser) ParseInteger(i interface{}, s *schema.Schema) (interface{}, err } switch s.Format { case "int32": - n32, err := strconv.Atoi(v) + val64, err := strconv.ParseInt(v, 10, 32) if err != nil { return 0, &ErrorDetail{ Message: fmt.Sprintf("invalid type, expected %v but got %v", s.Type, toType(i)), Field: "type", } } - n = int64(n32) + n = val64 default: var err error n, err = strconv.ParseInt(v, 10, 64)