You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
that test 'True', 'true' and '1' for a boolean query parameter.
The last one, '1', no longer passes validation.
Expected Behavior
This behavior has changed at some point after 0.16.x where the test passed. This came up attempting to update past 0.16.x where the test started failing due to CastingError.
As for expected behavior, it may be that the new behavior is more correct but it is also somewhat common to allow '1' in APIs.
# FIXME: don't cast data from media type deserializer
# See https://github.com/python-openapi/openapi-core/issues/706
ifisinstance(value, bool):
return
ifvalue.lower() notin ["false", "true"]:
raiseValueError("not a boolean format")
Anything else we need to know?
The main thing I want to point out is that forcebool is only ever called after validate which means that values other than 'true' and 'false' can never get to forcebool.
If this is on purpose, then I assume the way around this is to provide a custom BooleanCaster?
Or are there other suggested solutions if I do want to allow '1' in the API?
Would you like to implement a fix?
None
The text was updated successfully, but these errors were encountered:
Actual Behavior
I have API tests similar to
openapi-core/tests/unit/test_util.py
Lines 6 to 22 in b8f0644
'True'
,'true'
and'1'
for a boolean query parameter.The last one,
'1'
, no longer passes validation.Expected Behavior
This behavior has changed at some point after
0.16.x
where the test passed. This came up attempting to update past0.16.x
where the test started failing due toCastingError
.As for expected behavior, it may be that the new behavior is more correct but it is also somewhat common to allow
'1'
in APIs.The older versions used
forcebool
as the caster/validator but the current version first callsBooleanCaster.validate
before callingforcebool
.Steps to Reproduce
Pass for example
'1'
toBooleanCaster.__call__
.OpenAPI Core Version
0.19.2
OpenAPI Core Integration
django
Affected Area(s)
casting, validation
References
Old code:
openapi-core/openapi_core/casting/schemas/factories.py
Lines 19 to 23 in efaa5ac
openapi-core/openapi_core/util.py
Lines 7 to 17 in efaa5ac
Current code:
openapi-core/openapi_core/casting/schemas/__init__.py
Lines 25 to 34 in b8f0644
openapi-core/openapi_core/casting/schemas/casters.py
Lines 61 to 78 in 8e2c5a8
Anything else we need to know?
The main thing I want to point out is that
forcebool
is only ever called aftervalidate
which means that values other than'true'
and'false'
can never get toforcebool
.If this is on purpose, then I assume the way around this is to provide a custom
BooleanCaster
?Or are there other suggested solutions if I do want to allow
'1'
in the API?Would you like to implement a fix?
None
The text was updated successfully, but these errors were encountered: