Skip to content

Commit

Permalink
Merge pull request #1282 from sbrunner/fix-default-list
Browse files Browse the repository at this point in the history
Fix missing default on list
  • Loading branch information
sbrunner authored Dec 13, 2024
2 parents 0dca64a + 89016c8 commit 6f5069b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
21 changes: 13 additions & 8 deletions jsonschema_gentypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def name(self, python_version: tuple[int, ...]) -> str:

def depends_on(self, python_version: tuple[int, ...]) -> list[Type]:
"""Return the needed sub types."""
return [self.base] + self.sub_types + super().depends_on(python_version)
return [self.base, *self.sub_types, *super().depends_on(python_version)]


class UnionType(CombinedType):
Expand All @@ -376,7 +376,7 @@ def depends_on(self, python_version: tuple[int, ...]) -> list[Type]:
"""Return the needed sub types."""
if self._required_union(python_version):
return super().depends_on(python_version)
return self.sub_types + super().depends_on(python_version)
return [*self.sub_types, *super(CombinedType, self).depends_on(python_version)]

def name(self, python_version: tuple[int, ...]) -> str:
"""Return what we need to use the type."""
Expand All @@ -398,15 +398,20 @@ def __init__(self, sub_type: Type) -> None:
super().__init__(NativeType("Optional"), [sub_type])
self.sub_type = sub_type

def _required_optional(self, python_version: tuple[int, ...]) -> bool:
if python_version < (3, 10):
return True
return self.sub_type.name(python_version).startswith('"')

def depends_on(self, python_version: tuple[int, ...]) -> list[Type]:
"""Return the needed sub types."""
if python_version < (3, 10):
if self._required_optional(python_version):
return super().depends_on(python_version)
return [self.sub_type, *super().depends_on(python_version)]
return [self.sub_type, *super(CombinedType, self).depends_on(python_version)]

def name(self, python_version: tuple[int, ...]) -> str:
"""Return what we need to use the type."""
if python_version < (3, 10):
if self._required_optional(python_version):
return super().name(python_version)
return f"{self.sub_type.name(python_version)} | None"

Expand All @@ -430,7 +435,7 @@ def depends_on(self, python_version: tuple[int, ...]) -> list[Type]:
"""Return the needed sub types."""
if python_version < (3, 9):
return super().depends_on(python_version)
return [self.key_type, self.value_type]
return [self.key_type, self.value_type, *super(CombinedType, self).depends_on(python_version)]

def name(self, python_version: tuple[int, ...]) -> str:
"""Return what we need to use the type."""
Expand All @@ -456,7 +461,7 @@ def depends_on(self, python_version: tuple[int, ...]) -> list[Type]:
"""Return the needed sub types."""
if python_version < (3, 9):
return super().depends_on(python_version)
return [self.sub_type]
return [self.sub_type, *super(CombinedType, self).depends_on(python_version)]

def name(self, python_version: tuple[int, ...]) -> str:
"""Return what we need to use the type."""
Expand All @@ -481,7 +486,7 @@ def depends_on(self, python_version: tuple[int, ...]) -> list[Type]:
"""Return the needed sub types."""
if python_version < (3, 9):
return super().depends_on(python_version)
return self.sub_types
return [*self.sub_types, *super(CombinedType, self).depends_on(python_version)]

def name(self, python_version: tuple[int, ...]) -> str:
"""Return what we need to use the type."""
Expand Down
6 changes: 5 additions & 1 deletion jsonschema_gentypes/configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Automatically generated file from a JSON schema."""

from typing import Literal, TypedDict, Union
from typing import Any, Literal, TypedDict, Union

from typing_extensions import Required

Expand Down Expand Up @@ -118,6 +118,10 @@ class GenerateItem(TypedDict, total=False):
"""The values for the 'Get name properties' enum"""


PRE_COMMIT_ARGUMENTS_DEFAULT: list[Any] = []
""" Default value of the field path 'Pre-commit configuration arguments' """


PRE_COMMIT_ENABLE_DEFAULT = False
""" Default value of the field path 'Pre-commit configuration enable' """

Expand Down
4 changes: 4 additions & 0 deletions tests/openapi3.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,5 +707,9 @@ class _ExtentWithUniformAdditionalDimensionsSchemaTemporalGrid(TypedDict, total=
"""The values for the 'Coordinate reference system of the coordinates in the temporal extent' enum"""


_OGCAPICOLLECTIONSCOLLECTIONIDGETRESPONSE200_CRS_DEFAULT = ["http://www.opengis.net/def/crs/OGC/1.3/CRS84"]
""" Default value of the field path 'OgcapiCollectionsCollectionidGetResponse200 crs' """


_OGCAPICOLLECTIONSCOLLECTIONIDGETRESPONSE200_ITEMTYPE_DEFAULT = "unknown"
""" Default value of the field path 'OgcapiCollectionsCollectionidGetResponse200 itemType' """

0 comments on commit 6f5069b

Please sign in to comment.