From 3aa9982b23fa4218b07f188cfe93280a1dce4fa0 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Thu, 23 Apr 2015 18:19:08 +0800 Subject: [PATCH] Fixed issue that it will throw error when deserialize model in python client. --- .../src/main/resources/python/__init__model.mustache | 4 ++++ .../src/main/resources/python/swagger.mustache | 5 ++--- .../SwaggerPetstore/models/__init__.py | 12 ++++++++++++ .../SwaggerPetstore/swagger.py | 5 ++--- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/__init__model.mustache b/modules/swagger-codegen/src/main/resources/python/__init__model.mustache index 728aacbb9ab..93d18228d25 100644 --- a/modules/swagger-codegen/src/main/resources/python/__init__model.mustache +++ b/modules/swagger-codegen/src/main/resources/python/__init__model.mustache @@ -2,6 +2,10 @@ """Add all of the modules in the current directory to __all__""" import os +{{#models}}{{#model}} +from .{{classVarName}} import {{classname}} +{{/model}}{{/models}} + __all__ = [] for module in os.listdir(os.path.dirname(__file__)): diff --git a/modules/swagger-codegen/src/main/resources/python/swagger.mustache b/modules/swagger-codegen/src/main/resources/python/swagger.mustache index 76857b09ab7..10ac54d527d 100644 --- a/modules/swagger-codegen/src/main/resources/python/swagger.mustache +++ b/modules/swagger-codegen/src/main/resources/python/swagger.mustache @@ -17,8 +17,7 @@ import datetime import mimetypes import random import string - -from models import * +import models class ApiClient(object): @@ -211,7 +210,7 @@ class ApiClient(object): if (objClass in ['int', 'float', 'long', 'dict', 'list', 'str', 'bool', 'datetime']): objClass = eval(objClass) else: # not a native type, must be model class - objClass = eval(objClass + '.' + objClass) + objClass = eval('models.' + objClass) if objClass in [int, long, float, dict, list, str, bool]: return objClass(obj) diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/__init__.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/__init__.py index 728aacbb9ab..ce94c72a70c 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/__init__.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/__init__.py @@ -2,6 +2,18 @@ """Add all of the modules in the current directory to __all__""" import os + +from .user import User + +from .category import Category + +from .pet import Pet + +from .tag import Tag + +from .order import Order + + __all__ = [] for module in os.listdir(os.path.dirname(__file__)): diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py index 76857b09ab7..10ac54d527d 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py @@ -17,8 +17,7 @@ import datetime import mimetypes import random import string - -from models import * +import models class ApiClient(object): @@ -211,7 +210,7 @@ class ApiClient(object): if (objClass in ['int', 'float', 'long', 'dict', 'list', 'str', 'bool', 'datetime']): objClass = eval(objClass) else: # not a native type, must be model class - objClass = eval(objClass + '.' + objClass) + objClass = eval('models.' + objClass) if objClass in [int, long, float, dict, list, str, bool]: return objClass(obj)