From 2c939b03b40e18ce0c100ccff33a20e3a46a6658 Mon Sep 17 00:00:00 2001 From: Takuro Wada Date: Wed, 8 Jun 2016 23:48:34 +0900 Subject: [PATCH] Apply readWriteVars to constructor in python/model.mustach --- .../src/main/resources/python/gitignore.mustache | 2 ++ .../src/main/resources/python/model.mustache | 9 ++++++--- samples/client/petstore/python/README.md | 12 ++++++------ .../petstore/python/petstore_api/models/name.py | 6 +++--- .../python/petstore_api/models/read_only_first.py | 4 ++-- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/gitignore.mustache b/modules/swagger-codegen/src/main/resources/python/gitignore.mustache index 1dbc687de01..a655050c263 100644 --- a/modules/swagger-codegen/src/main/resources/python/gitignore.mustache +++ b/modules/swagger-codegen/src/main/resources/python/gitignore.mustache @@ -44,6 +44,8 @@ nosetests.xml coverage.xml *,cover .hypothesis/ +venv/ +.python-version # Translations *.mo diff --git a/modules/swagger-codegen/src/main/resources/python/model.mustache b/modules/swagger-codegen/src/main/resources/python/model.mustache index 1239ef8557d..4a8cf2a4cc2 100644 --- a/modules/swagger-codegen/src/main/resources/python/model.mustache +++ b/modules/swagger-codegen/src/main/resources/python/model.mustache @@ -14,7 +14,7 @@ class {{classname}}(object): NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. """ - def __init__(self{{#vars}}, {{name}}={{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{/vars}}): + def __init__(self{{#readWriteVars}}, {{name}}={{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{/readWriteVars}}): """ {{classname}} - a model defined in Swagger @@ -33,9 +33,12 @@ class {{classname}}(object): {{/hasMore}}{{/vars}} } -{{#vars}} +{{#readOnlyVars}} + self._{{name}} = {{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}None{{/defaultValue}} +{{/readOnlyVars}} +{{#readWriteVars}} self._{{name}} = {{name}} -{{/vars}} +{{/readWriteVars}} {{#vars}}{{#-first}} {{/-first}} @property diff --git a/samples/client/petstore/python/README.md b/samples/client/petstore/python/README.md index 15d55317325..a25525100af 100644 --- a/samples/client/petstore/python/README.md +++ b/samples/client/petstore/python/README.md @@ -5,7 +5,7 @@ This Python package is automatically generated by the [Swagger Codegen](https:// - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-06-08T10:26:51.066+08:00 +- Build date: 2016-06-08T23:40:51.798+09:00 - Build package: class io.swagger.codegen.languages.PythonClientCodegen ## Requirements. @@ -24,7 +24,7 @@ pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git Then import the package: ```python -import swagger_client +import petstore_api ``` ### Setuptools @@ -38,7 +38,7 @@ python setup.py install --user Then import the package: ```python -import swagger_client +import petstore_api ``` ## Getting Started @@ -47,11 +47,11 @@ Please follow the [installation procedure](#installation--usage) and then run th ```python import time -import swagger_client -from swagger_client.rest import ApiException +import petstore_api +from petstore_api.rest import ApiException from pprint import pprint # create an instance of the API class -api_instance = swagger_client.FakeApi +api_instance = petstore_api.FakeApi number = 3.4 # float | None double = 1.2 # float | None string = 'string_example' # str | None diff --git a/samples/client/petstore/python/petstore_api/models/name.py b/samples/client/petstore/python/petstore_api/models/name.py index 2cff0bfc231..bddb37ed6ec 100644 --- a/samples/client/petstore/python/petstore_api/models/name.py +++ b/samples/client/petstore/python/petstore_api/models/name.py @@ -32,7 +32,7 @@ class Name(object): NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. """ - def __init__(self, name=None, snake_case=None, _property=None, _123_number=None): + def __init__(self, name=None, _property=None): """ Name - a model defined in Swagger @@ -55,10 +55,10 @@ class Name(object): '_123_number': '123Number' } + self._snake_case = None + self.__123_number = None self._name = name - self._snake_case = snake_case self.__property = _property - self.__123_number = _123_number @property def name(self): diff --git a/samples/client/petstore/python/petstore_api/models/read_only_first.py b/samples/client/petstore/python/petstore_api/models/read_only_first.py index b1ca04f4a09..d7a29c0fb89 100644 --- a/samples/client/petstore/python/petstore_api/models/read_only_first.py +++ b/samples/client/petstore/python/petstore_api/models/read_only_first.py @@ -32,7 +32,7 @@ class ReadOnlyFirst(object): NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. """ - def __init__(self, bar=None, baz=None): + def __init__(self, baz=None): """ ReadOnlyFirst - a model defined in Swagger @@ -51,7 +51,7 @@ class ReadOnlyFirst(object): 'baz': 'baz' } - self._bar = bar + self._bar = None self._baz = baz @property