From 43ca5fcac9b4b17de6ecca117e3a39bcd243a32d Mon Sep 17 00:00:00 2001 From: "Zishun (Zack) WEI" <56001105+zishunwei@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:39:19 +0800 Subject: [PATCH] Fix issue 18088: Missing the important statement for Datetime in Python binding generation (#18173) * fix issue 18088 * update samples --- .../codegen/languages/AbstractPythonCodegen.java | 5 +++-- .../openapi_client/api/auth_api.py | 1 + .../client/echo_api/python/openapi_client/api/auth_api.py | 1 + .../petstore/python-aiohttp/petstore_api/api/store_api.py | 3 ++- .../client/petstore/python/petstore_api/api/store_api.py | 3 ++- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java index 6574bdc9a5a..de727dbc05e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java @@ -1056,8 +1056,8 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co Set exampleImports, Set postponedModelImports, Set postponedExampleImports, + PythonImports moduleImports, String classname) { - PythonImports moduleImports = new PythonImports(); PydanticType pt = new PydanticType( modelImports, exampleImports, @@ -1250,6 +1250,7 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co exampleImports, postponedModelImports, postponedExampleImports, + moduleImports, null ); } @@ -2171,7 +2172,7 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co // TODO process the first one only at the moment if (cmt != null) // TODO: don't loop back to the deprecated getPydanticType method - return getPydanticType(cmt.getSchema(), modelImports, exampleImports, postponedModelImports, postponedExampleImports, classname); + return getPydanticType(cmt.getSchema(), modelImports, exampleImports, postponedModelImports, postponedExampleImports, moduleImports, classname); } throw new RuntimeException("Error! Failed to process getPydanticType when getting the content: " + cp); } else { diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/auth_api.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/auth_api.py index 3e114086807..dfd24668c5e 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/auth_api.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/auth_api.py @@ -17,6 +17,7 @@ from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union from typing_extensions import Annotated +from pydantic import StrictStr from openapi_client.api_client import ApiClient, RequestSerialized from openapi_client.api_response import ApiResponse diff --git a/samples/client/echo_api/python/openapi_client/api/auth_api.py b/samples/client/echo_api/python/openapi_client/api/auth_api.py index 3e114086807..dfd24668c5e 100644 --- a/samples/client/echo_api/python/openapi_client/api/auth_api.py +++ b/samples/client/echo_api/python/openapi_client/api/auth_api.py @@ -17,6 +17,7 @@ from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union from typing_extensions import Annotated +from pydantic import StrictStr from openapi_client.api_client import ApiClient, RequestSerialized from openapi_client.api_response import ApiResponse diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/store_api.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/store_api.py index 1f84e3d5a4a..d4150f7f9b9 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/store_api.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/store_api.py @@ -16,7 +16,8 @@ from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union from typing_extensions import Annotated -from pydantic import Field, StrictStr +from pydantic import Field, StrictInt, StrictStr +from typing import Dict from typing_extensions import Annotated from petstore_api.models.order import Order diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/store_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/store_api.py index bd1108c901c..c50d82d6a5b 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/api/store_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/store_api.py @@ -16,7 +16,8 @@ from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt from typing import Any, Dict, List, Optional, Tuple, Union from typing_extensions import Annotated -from pydantic import Field, StrictStr +from pydantic import Field, StrictInt, StrictStr +from typing import Dict from typing_extensions import Annotated from petstore_api.models.order import Order