Skip to content

Range-check floats in is_int32 and is_int64 format checkers - #309

Open
kitkatt7 wants to merge 1 commit into
python-openapi:masterfrom
kitkatt7:int-format-float-range
Open

kitkatt7 wants to merge 1 commit into
python-openapi:masterfrom
kitkatt7:int-format-float-range

Conversation

@kitkatt7

Copy link
Copy Markdown

is_int32 and is_int64 only range-check int instances and return True for anything else, floats included:

  • OAS 3.1/3.2 treat integral floats as integers (Draft 2020-12), so 1e10 or 2147483648.0 passes {"type": "integer", "format": "int32"} while 10000000000 is rejected, and 1e19 passes int64 the same way
  • json.loads turns 1e10 into a float, so JSON bodies hit this directly: with openapi-core 0.23.1 and a 3.1 or 3.2 spec, a request body {"qty": 1e10} validates against an int32 field and reaches the handler as 10000000000.0
  • OAS 3.0 is only affected for type: number or untyped schemas with an int format, since its integer type check already rejects floats

Floats now go through the same comparison: in-range values (including 3.12, which test_formats_ignored expects to pass) are unchanged, and out-of-range values, inf and nan are rejected.

is_int32 and is_int64 skipped the range check for anything that is not
an int. The OAS 3.1/3.2 type checker treats integral floats as integers,
so a JSON value such as 1e10 or 2147483648.0 passed
{type: integer, format: int32} while 10000000000 was rejected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant