From 9e96dffb3c7fdf88dd4d7de7ea46bf1365ff8602 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Wed, 6 Apr 2022 23:02:47 -0700 Subject: [PATCH] fix Signed-off-by: Jess Frazelle --- generate/generate.py | 73 ++++++++++++++----- .../api_call_with_price_results_page.py | 6 +- kittycad/models/api_token_results_page.py | 6 +- kittycad/models/extended_user_results_page.py | 6 +- .../models/file_conversion_results_page.py | 6 +- kittycad/models/user_results_page.py | 6 +- 6 files changed, 76 insertions(+), 27 deletions(-) diff --git a/generate/generate.py b/generate/generate.py index bf9ac82f9..c843e5c18 100755 --- a/generate/generate.py +++ b/generate/generate.py @@ -730,10 +730,23 @@ def generateType(path: str, name: str, schema: dict): property_name + ": Union[Unset, bool] = False\n") elif property_type == 'array': - f.write( - "\t" + - property_name + - ": Union[Unset, array] = []\n") + if 'items' in property_schema: + if '$ref' in property_schema['items']: + property_type = property_schema['items']['$ref'] + property_type = property_type.replace( + '#/components/schemas/', '') + f.write( + "\t" + + property_name + + ": Union[Unset, List[" + + property_type + + "]] = UNSET\n") + else: + print(" array: ", [property_schema]) + print(" array: ", [property_schema['items']]) + raise Exception("Unknown array type") + else: + raise Exception("Unknown array type") else: raise Exception(" unknown type: ", property_type) elif '$ref' in property_schema: @@ -821,12 +834,29 @@ def generateType(path: str, name: str, schema: dict): property_name + "\n") elif property_type == 'array': - f.write( - "\t\t" + - property_name + - " = self." + - property_name + - "\n") + if 'items' in property_schema: + if '$ref' in property_schema['items']: + property_type = property_schema['items']['$ref'] + property_type = property_type.replace( + '#/components/schemas/', '') + f.write( + "\t\t" + + property_name + + ": Union[Unset, List[" + + property_type + + "]] = UNSET\n") + f.write( + "\t\tif not isinstance(self." + property_name + ", Unset):\n") + f.write( + "\t\t\t" + + property_name + + " = self." + + property_name + + "\n") + else: + print(" array: ", [property_schema]) + print(" array: ", [property_schema['items']]) + raise Exception("Unknown array type") else: raise Exception(" unknown type: ", property_type) elif '$ref' in property_schema: @@ -958,13 +988,22 @@ def generateType(path: str, name: str, schema: dict): "\", UNSET)\n") f.write("\n") elif property_type == 'array': - f.write( - "\t\t" + - property_name + - " = d.pop(\"" + - property_name + - "\", UNSET)\n") - f.write("\n") + if 'items' in property_schema: + if '$ref' in property_schema['items']: + property_type = property_schema['items']['$ref'] + property_type = property_type.replace( + '#/components/schemas/', '') + f.write( + "\t\t" + + property_name + + " = cast(List["+ property_type + "], d.pop(\"" + + property_name + + "\", UNSET))\n") + f.write("\n") + else: + print(" array: ", [property_schema]) + print(" array: ", [property_schema['items']]) + raise Exception("Unknown array type") else: print(" unknown type: ", property_type) raise Exception(" unknown type: ", property_type) diff --git a/kittycad/models/api_call_with_price_results_page.py b/kittycad/models/api_call_with_price_results_page.py index 4482051cf..3be36da10 100644 --- a/kittycad/models/api_call_with_price_results_page.py +++ b/kittycad/models/api_call_with_price_results_page.py @@ -10,13 +10,15 @@ T = TypeVar("T", bound="ApiCallWithPriceResultsPage") @attr.s(auto_attribs=True) class ApiCallWithPriceResultsPage: """ """ - items: Union[Unset, array] = [] + items: Union[Unset, List[ApiCallWithPrice]] = UNSET next_page: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: - items = self.items + items: Union[Unset, List[ApiCallWithPrice]] = UNSET + if not isinstance(self.items, Unset): + items = self.items next_page = self.next_page field_dict: Dict[str, Any] = {} diff --git a/kittycad/models/api_token_results_page.py b/kittycad/models/api_token_results_page.py index 7610cdf57..1e11a4fb8 100644 --- a/kittycad/models/api_token_results_page.py +++ b/kittycad/models/api_token_results_page.py @@ -10,13 +10,15 @@ T = TypeVar("T", bound="ApiTokenResultsPage") @attr.s(auto_attribs=True) class ApiTokenResultsPage: """ """ - items: Union[Unset, array] = [] + items: Union[Unset, List[ApiToken]] = UNSET next_page: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: - items = self.items + items: Union[Unset, List[ApiToken]] = UNSET + if not isinstance(self.items, Unset): + items = self.items next_page = self.next_page field_dict: Dict[str, Any] = {} diff --git a/kittycad/models/extended_user_results_page.py b/kittycad/models/extended_user_results_page.py index 28e9c8594..14f1bc9ce 100644 --- a/kittycad/models/extended_user_results_page.py +++ b/kittycad/models/extended_user_results_page.py @@ -10,13 +10,15 @@ T = TypeVar("T", bound="ExtendedUserResultsPage") @attr.s(auto_attribs=True) class ExtendedUserResultsPage: """ """ - items: Union[Unset, array] = [] + items: Union[Unset, List[ExtendedUser]] = UNSET next_page: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: - items = self.items + items: Union[Unset, List[ExtendedUser]] = UNSET + if not isinstance(self.items, Unset): + items = self.items next_page = self.next_page field_dict: Dict[str, Any] = {} diff --git a/kittycad/models/file_conversion_results_page.py b/kittycad/models/file_conversion_results_page.py index 4862e8aae..67bc9d68a 100644 --- a/kittycad/models/file_conversion_results_page.py +++ b/kittycad/models/file_conversion_results_page.py @@ -10,13 +10,15 @@ T = TypeVar("T", bound="FileConversionResultsPage") @attr.s(auto_attribs=True) class FileConversionResultsPage: """ """ - items: Union[Unset, array] = [] + items: Union[Unset, List[FileConversion]] = UNSET next_page: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: - items = self.items + items: Union[Unset, List[FileConversion]] = UNSET + if not isinstance(self.items, Unset): + items = self.items next_page = self.next_page field_dict: Dict[str, Any] = {} diff --git a/kittycad/models/user_results_page.py b/kittycad/models/user_results_page.py index b92efa027..ba687ff7c 100644 --- a/kittycad/models/user_results_page.py +++ b/kittycad/models/user_results_page.py @@ -10,13 +10,15 @@ T = TypeVar("T", bound="UserResultsPage") @attr.s(auto_attribs=True) class UserResultsPage: """ """ - items: Union[Unset, array] = [] + items: Union[Unset, List[User]] = UNSET next_page: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: - items = self.items + items: Union[Unset, List[User]] = UNSET + if not isinstance(self.items, Unset): + items = self.items next_page = self.next_page field_dict: Dict[str, Any] = {}