Skip to content

Commit 9dc2cac

Browse files
committed
openapi_schema_pydantic / schema / set nullable type to bool
1 parent 63d0bd7 commit 9dc2cac

File tree

4 files changed

+6
-16
lines changed

4 files changed

+6
-16
lines changed

openapi_python_client/parser/properties/property.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Property:
2222

2323
name: str
2424
required: bool
25-
nullable: bool = attr.ib(converter=utils.optin_bool_to_bool_converter)
25+
nullable: bool
2626
_type_string: ClassVar[str] = ""
2727
_json_type_string: ClassVar[str] = "" # Type of the property after JSON serialization
2828
default: Optional[str] = attr.ib()

openapi_python_client/schema/openapi_schema_pydantic/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ class Schema(BaseModel):
406406
Other than the JSON Schema subset fields, the following fields MAY be used for further schema documentation:
407407
"""
408408

409-
nullable: Optional[bool] = None
409+
nullable: bool = False
410410
"""
411411
A `true` value adds `"null"` to the allowed type specified by the `type` keyword,
412412
only if `type` is explicitly defined within the same Schema Object.

openapi_python_client/utils.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import builtins
22
import re
33
from keyword import iskeyword
4-
from typing import List, Optional
4+
from typing import List
55

66
delimiters = " _-"
77

@@ -73,13 +73,3 @@ def to_valid_python_identifier(value: str) -> str:
7373
return new_value
7474

7575
return f"{FIELD_PREFIX}{new_value}"
76-
77-
78-
def optin_bool_to_bool_converter(value: Optional[bool]) -> bool:
79-
"""
80-
Given an Option[bool] return a bool
81-
None are converted to False
82-
"""
83-
if value is None:
84-
return False
85-
return value

tests/test_parser/test_properties/test_init.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,14 +974,14 @@ def test_property_from_data_union(self, mocker):
974974
name=name, required=required, data=data, schemas=Schemas(), parent_name="parent", config=MagicMock()
975975
)
976976

977-
FloatProperty.assert_called_once_with(name=name, required=required, default=0.0, nullable=None)
978-
IntProperty.assert_called_once_with(name=name, required=required, default=0, nullable=None)
977+
FloatProperty.assert_called_once_with(name=name, required=required, default=0.0, nullable=False)
978+
IntProperty.assert_called_once_with(name=name, required=required, default=0, nullable=False)
979979
UnionProperty.assert_called_once_with(
980980
name=name,
981981
required=required,
982982
default=None,
983983
inner_properties=[FloatProperty.return_value, IntProperty.return_value],
984-
nullable=None,
984+
nullable=False,
985985
)
986986
assert p == UnionProperty.return_value
987987
assert s == Schemas()

0 commit comments

Comments
 (0)