Skip to content

Commit 2d4365c

Browse files
committed
fix: Don't allow mixed types in enums.
1 parent f5b5ce8 commit 2d4365c

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

Diff for: openapi_python_client/parser/properties/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def build_enum_property(
296296
name: str,
297297
required: bool,
298298
schemas: Schemas,
299-
enum: List[Union[str, int]],
299+
enum: Union[List[str], List[int]],
300300
parent_name: Optional[str],
301301
config: Config,
302302
) -> Tuple[Union[EnumProperty, PropertyError], Schemas]:

Diff for: openapi_python_client/parser/properties/enum_property.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__all__ = ["EnumProperty"]
22

3-
from typing import Any, ClassVar, Dict, List, Optional, Set, Type, Union
3+
from typing import Any, ClassVar, Dict, List, Optional, Set, Type, Union, cast
44

55
import attr
66

@@ -41,11 +41,12 @@ def get_imports(self, *, prefix: str) -> Set[str]:
4141
return imports
4242

4343
@staticmethod
44-
def values_from_list(values: List[ValueType]) -> Dict[str, ValueType]:
44+
def values_from_list(values: Union[List[str], List[int]]) -> Dict[str, ValueType]:
4545
"""Convert a list of values into dict of {name: value}"""
4646
output: Dict[str, ValueType] = {}
4747

4848
for i, value in enumerate(values):
49+
value = cast(Union[str, int], value)
4950
if isinstance(value, int):
5051
if value < 0:
5152
output[f"VALUE_NEGATIVE_{-value}"] = value

Diff for: openapi_python_client/schema/openapi_schema_pydantic/schema.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict, List, Optional, Union
22

3-
from pydantic import BaseModel, Field
3+
from pydantic import BaseModel, Field, StrictInt, StrictStr
44

55
from ..data_type import DataType
66
from .discriminator import Discriminator
@@ -35,7 +35,7 @@ class Schema(BaseModel):
3535
maxProperties: Optional[int] = Field(default=None, ge=0)
3636
minProperties: Optional[int] = Field(default=None, ge=0)
3737
required: Optional[List[str]] = Field(default=None, min_items=1)
38-
enum: Optional[List[Union[str, int]]] = Field(default=None, min_items=1)
38+
enum: Union[None, List[StrictInt], List[StrictStr]] = Field(default=None, min_items=1)
3939
type: Optional[DataType] = Field(default=None)
4040
allOf: Optional[List[Union[Reference, "Schema"]]] = None
4141
oneOf: List[Union[Reference, "Schema"]] = []

0 commit comments

Comments
 (0)