From 21519437b3f917fb9648bd657167660a277065a7 Mon Sep 17 00:00:00 2001 From: ilayu Date: Tue, 14 Apr 2026 14:40:08 +0300 Subject: [PATCH] Fix python model dict array generation --- .gitignore | 3 +++ .../python-fastapi/model_generic.mustache | 14 ++++++-------- .../main/resources/python/model_generic.mustache | 14 ++++++-------- .../petstore_api/models/map_of_array_of_model.py | 14 ++++++-------- ...d_dict_with_additional_model_list_properties.py | 14 ++++++-------- .../petstore_api/models/map_of_array_of_model.py | 14 ++++++-------- ...d_dict_with_additional_model_list_properties.py | 14 ++++++-------- .../petstore_api/models/map_of_array_of_model.py | 14 ++++++-------- ...d_dict_with_additional_model_list_properties.py | 14 ++++++-------- .../petstore_api/models/map_of_array_of_model.py | 14 ++++++-------- ...d_dict_with_additional_model_list_properties.py | 14 ++++++-------- 11 files changed, 63 insertions(+), 80 deletions(-) diff --git a/.gitignore b/.gitignore index 758dbfdbde47..58c0341b3f7d 100644 --- a/.gitignore +++ b/.gitignore @@ -309,3 +309,6 @@ samples/client/petstore/ocaml-recursion-test/_build/ # jetbrain http client samples/client/jetbrains/adyen/checkout71/http/client/Apis/http-client.private.env.json + +# Generated by the run-in-docker.sh +\?/ diff --git a/modules/openapi-generator/src/main/resources/python-fastapi/model_generic.mustache b/modules/openapi-generator/src/main/resources/python-fastapi/model_generic.mustache index 41354ee62410..e5e64a08ebeb 100644 --- a/modules/openapi-generator/src/main/resources/python-fastapi/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python-fastapi/model_generic.mustache @@ -317,14 +317,12 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} else None{{^-last}},{{/-last}} {{/items.isMap}} {{#items.isArray}} - "{{{baseName}}}": dict( - (_k, - [{{{items.items.dataType}}}.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("{{{baseName}}}").items() - ){{^-last}},{{/-last}} + "{{{baseName}}}": { + _k: [{{{items.items.dataType}}}.from_dict(_item) for _item in _v] if _v is not None else None + for _k, _v in obj["{{{baseName}}}"].items() + } + if obj.get("{{{baseName}}}") is not None + else None{{^-last}},{{/-last}} {{/items.isArray}} {{/items.isContainer}} {{^items.isContainer}} diff --git a/modules/openapi-generator/src/main/resources/python/model_generic.mustache b/modules/openapi-generator/src/main/resources/python/model_generic.mustache index 0bea1daa40bd..dffa743ba9cb 100644 --- a/modules/openapi-generator/src/main/resources/python/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_generic.mustache @@ -380,14 +380,12 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} else None{{^-last}},{{/-last}} {{/items.isMap}} {{#items.isArray}} - "{{{baseName}}}": dict( - (_k, - [{{{items.items.dataType}}}.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("{{{baseName}}}", {}).items() - ){{^-last}},{{/-last}} + "{{{baseName}}}": { + _k: [{{{items.items.dataType}}}.from_dict(_item) for _item in _v] if _v is not None else None + for _k, _v in obj["{{{baseName}}}"].items() + } + if obj.get("{{{baseName}}}") is not None + else None{{^-last}},{{/-last}} {{/items.isArray}} {{/items.isContainer}} {{^items.isContainer}} diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_of_array_of_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_of_array_of_model.py index 9471116f72a6..8f8d882c67b3 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_of_array_of_model.py @@ -91,14 +91,12 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: return cls.model_validate(obj) _obj = cls.model_validate({ - "shopIdToOrgOnlineLipMap": dict( - (_k, - [Tag.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("shopIdToOrgOnlineLipMap", {}).items() - ) + "shopIdToOrgOnlineLipMap": { + _k: [Tag.from_dict(_item) for _item in _v] if _v is not None else None + for _k, _v in obj["shopIdToOrgOnlineLipMap"].items() + } + if obj.get("shopIdToOrgOnlineLipMap") is not None + else None }) return _obj diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py index db282d09ac6d..4c79fe8bc7e5 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py @@ -91,14 +91,12 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: return cls.model_validate(obj) _obj = cls.model_validate({ - "dictProperty": dict( - (_k, - [CreatureInfo.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("dictProperty", {}).items() - ) + "dictProperty": { + _k: [CreatureInfo.from_dict(_item) for _item in _v] if _v is not None else None + for _k, _v in obj["dictProperty"].items() + } + if obj.get("dictProperty") is not None + else None }) return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/map_of_array_of_model.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/map_of_array_of_model.py index 9471116f72a6..8f8d882c67b3 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/map_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/map_of_array_of_model.py @@ -91,14 +91,12 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: return cls.model_validate(obj) _obj = cls.model_validate({ - "shopIdToOrgOnlineLipMap": dict( - (_k, - [Tag.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("shopIdToOrgOnlineLipMap", {}).items() - ) + "shopIdToOrgOnlineLipMap": { + _k: [Tag.from_dict(_item) for _item in _v] if _v is not None else None + for _k, _v in obj["shopIdToOrgOnlineLipMap"].items() + } + if obj.get("shopIdToOrgOnlineLipMap") is not None + else None }) return _obj diff --git a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py index db282d09ac6d..4c79fe8bc7e5 100644 --- a/samples/openapi3/client/petstore/python-httpx/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py +++ b/samples/openapi3/client/petstore/python-httpx/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py @@ -91,14 +91,12 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: return cls.model_validate(obj) _obj = cls.model_validate({ - "dictProperty": dict( - (_k, - [CreatureInfo.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("dictProperty", {}).items() - ) + "dictProperty": { + _k: [CreatureInfo.from_dict(_item) for _item in _v] if _v is not None else None + for _k, _v in obj["dictProperty"].items() + } + if obj.get("dictProperty") is not None + else None }) return _obj diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/map_of_array_of_model.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/map_of_array_of_model.py index 349fbdf99b8e..c6018ae272c6 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/map_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/map_of_array_of_model.py @@ -99,14 +99,12 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: return cls.model_validate(obj) _obj = cls.model_validate({ - "shopIdToOrgOnlineLipMap": dict( - (_k, - [Tag.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("shopIdToOrgOnlineLipMap", {}).items() - ) + "shopIdToOrgOnlineLipMap": { + _k: [Tag.from_dict(_item) for _item in _v] if _v is not None else None + for _k, _v in obj["shopIdToOrgOnlineLipMap"].items() + } + if obj.get("shopIdToOrgOnlineLipMap") is not None + else None }) # store additional fields in additional_properties for _key in obj.keys(): diff --git a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py index 26a6c9e640a1..cf6878baa1b9 100644 --- a/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py +++ b/samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py @@ -99,14 +99,12 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: return cls.model_validate(obj) _obj = cls.model_validate({ - "dictProperty": dict( - (_k, - [CreatureInfo.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("dictProperty", {}).items() - ) + "dictProperty": { + _k: [CreatureInfo.from_dict(_item) for _item in _v] if _v is not None else None + for _k, _v in obj["dictProperty"].items() + } + if obj.get("dictProperty") is not None + else None }) # store additional fields in additional_properties for _key in obj.keys(): diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/map_of_array_of_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/map_of_array_of_model.py index 349fbdf99b8e..c6018ae272c6 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/map_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/map_of_array_of_model.py @@ -99,14 +99,12 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: return cls.model_validate(obj) _obj = cls.model_validate({ - "shopIdToOrgOnlineLipMap": dict( - (_k, - [Tag.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("shopIdToOrgOnlineLipMap", {}).items() - ) + "shopIdToOrgOnlineLipMap": { + _k: [Tag.from_dict(_item) for _item in _v] if _v is not None else None + for _k, _v in obj["shopIdToOrgOnlineLipMap"].items() + } + if obj.get("shopIdToOrgOnlineLipMap") is not None + else None }) # store additional fields in additional_properties for _key in obj.keys(): diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py b/samples/openapi3/client/petstore/python/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py index 26a6c9e640a1..cf6878baa1b9 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py @@ -99,14 +99,12 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: return cls.model_validate(obj) _obj = cls.model_validate({ - "dictProperty": dict( - (_k, - [CreatureInfo.from_dict(_item) for _item in _v] - if _v is not None - else None - ) - for _k, _v in obj.get("dictProperty", {}).items() - ) + "dictProperty": { + _k: [CreatureInfo.from_dict(_item) for _item in _v] if _v is not None else None + for _k, _v in obj["dictProperty"].items() + } + if obj.get("dictProperty") is not None + else None }) # store additional fields in additional_properties for _key in obj.keys():