diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PythonClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PythonClientCodegen.java index c578e049be..b28c0ccf75 100755 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PythonClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PythonClientCodegen.java @@ -7,7 +7,9 @@ import java.io.File; import java.util.*; public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig { - String module = "client"; + protected String module = "SwaggerPetstore"; + protected String invokerPackage; + protected String eggPackage; public CodegenType getTag() { return CodegenType.CLIENT; @@ -23,13 +25,17 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig public PythonClientCodegen() { super(); + + eggPackage = module + "-python"; + invokerPackage = eggPackage + "/" + module; + outputFolder = "generated-code/python"; modelTemplateFiles.put("model.mustache", ".py"); apiTemplateFiles.put("api.mustache", ".py"); templateDir = "python"; - apiPackage = module; - modelPackage = module + ".models"; + apiPackage = invokerPackage; + modelPackage = invokerPackage + ".models"; languageSpecificPrimitives.clear(); languageSpecificPrimitives.add("int"); @@ -59,9 +65,12 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig "print", "class", "exec", "in", "raise", "continue", "finally", "is", "return", "def", "for", "lambda", "try")); - supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); - supportingFiles.add(new SupportingFile("swagger.mustache", module, "swagger.py")); - supportingFiles.add(new SupportingFile("__init__package.mustache", module, "__init__.py")); + additionalProperties.put("module", module); + + supportingFiles.add(new SupportingFile("README.mustache", eggPackage, "README.md")); + supportingFiles.add(new SupportingFile("setup.mustache", eggPackage, "setup.py")); + supportingFiles.add(new SupportingFile("swagger.mustache", invokerPackage, "swagger.py")); + supportingFiles.add(new SupportingFile("__init__package.mustache", invokerPackage, "__init__.py")); supportingFiles.add(new SupportingFile("__init__model.mustache", modelPackage.replace('.', File.separatorChar), "__init__.py")); } diff --git a/modules/swagger-codegen/src/main/resources/python/README.mustache b/modules/swagger-codegen/src/main/resources/python/README.mustache index cf1f7142bc..3b69aba0f8 100644 --- a/modules/swagger-codegen/src/main/resources/python/README.mustache +++ b/modules/swagger-codegen/src/main/resources/python/README.mustache @@ -1,25 +1,42 @@ -# Swagger Generated Python client +## Requirements. +Python 2.7 and later. +## Setuptools +You can install the bindings via [Setuptools](http://pypi.python.org/pypi/setuptools). -Usage example, based on the swagger petstore: +```sh +python setup.py install +``` + +Or you can install from Github via pip: + +```sh +pip install git+https://github.com/geekerzp/SwaggerPetstore-python.git +``` + +To use the bindings, import the pacakge: ```python -# include the client module -from client import * - -# build a client connection. In this example, we are passing the hostname as arg0, and -# sending a header with name `api_key` and value `special-key` on each call to the api. - -client = swagger.ApiClient('http://petstore.swagger.io/v2', 'api_key', 'special-key') - -# create the PetApi class with the client we just created -petApi = PetApi.PetApi(client) - -# call the API and fetch a pet, with petId=3 -pet = petApi.getPetById(petId=3) - -# write it into pretty JSON -json = client.sanitizeForSerialization(pet) -print json -{'category': {'category': None, 'status': None, 'name': 'string', 'tags': None, 'photoUrls': None, 'id': 0L}, 'status': {'category': None, 'status': None, 'name': None, 'tags': None, 'photoUrls': None, 'id': None}, 'name': 'foogly', 'tags': [{'id': 0L, 'name': 'string'}], 'photoUrls': ['string'], 'id': 3L} +import SwaggerPetstore ``` + +## Manual Installation +If you do not wish to use setuptools, you can download the latest release. +Then, to use the bindings, import the package: + +```python +import path.to.SwaggerPetstore-python.SwaggerPetstore +``` + +## Getting Started + +TODO + +## Documentation + +TODO + +## Tests + +TODO + diff --git a/modules/swagger-codegen/src/main/resources/python/setup.mustache b/modules/swagger-codegen/src/main/resources/python/setup.mustache new file mode 100644 index 0000000000..d10da4c68d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/python/setup.mustache @@ -0,0 +1,32 @@ +import sys +from setuptools import setup, find_packages + +{{#apiInfo}}{{#apis}}{{^hasMore}} + +# To install the library, open a Terminal shell, then run this +# file by typing: +# +# python setup.py install +# +# You need to have the setuptools module installed. +# Try reading the setuptools documentation: +# http://pypi.python.org/pypi/setuptools + +REQUIRES = [] + +setup( + name="{{module}}", + version="{{version}}", + description="{{appName}}", + author_email="{{infoEmail}}", + url="{{infoUrl}}", + keywords=["Swagger", "{{appName}}"], + install_requires=REQUIRES, + packages=find_packages(), + include_package_data=True, + long_description="""\ + {{appDescription}} + """ +) + +{{/hasMore}}{{/apis}}{{/apiInfo}} diff --git a/samples/client/petstore/python/README.md b/samples/client/petstore/python/README.md deleted file mode 100644 index cf1f7142bc..0000000000 --- a/samples/client/petstore/python/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# Swagger Generated Python client - - -Usage example, based on the swagger petstore: - -```python -# include the client module -from client import * - -# build a client connection. In this example, we are passing the hostname as arg0, and -# sending a header with name `api_key` and value `special-key` on each call to the api. - -client = swagger.ApiClient('http://petstore.swagger.io/v2', 'api_key', 'special-key') - -# create the PetApi class with the client we just created -petApi = PetApi.PetApi(client) - -# call the API and fetch a pet, with petId=3 -pet = petApi.getPetById(petId=3) - -# write it into pretty JSON -json = client.sanitizeForSerialization(pet) -print json -{'category': {'category': None, 'status': None, 'name': 'string', 'tags': None, 'photoUrls': None, 'id': 0L}, 'status': {'category': None, 'status': None, 'name': None, 'tags': None, 'photoUrls': None, 'id': None}, 'name': 'foogly', 'tags': [{'id': 0L, 'name': 'string'}], 'photoUrls': ['string'], 'id': 3L} -``` diff --git a/samples/client/petstore/python/SwaggerPetstore-python/README.md b/samples/client/petstore/python/SwaggerPetstore-python/README.md new file mode 100644 index 0000000000..3b69aba0f8 --- /dev/null +++ b/samples/client/petstore/python/SwaggerPetstore-python/README.md @@ -0,0 +1,42 @@ +## Requirements. +Python 2.7 and later. + +## Setuptools +You can install the bindings via [Setuptools](http://pypi.python.org/pypi/setuptools). + +```sh +python setup.py install +``` + +Or you can install from Github via pip: + +```sh +pip install git+https://github.com/geekerzp/SwaggerPetstore-python.git +``` + +To use the bindings, import the pacakge: + +```python +import SwaggerPetstore +``` + +## Manual Installation +If you do not wish to use setuptools, you can download the latest release. +Then, to use the bindings, import the package: + +```python +import path.to.SwaggerPetstore-python.SwaggerPetstore +``` + +## Getting Started + +TODO + +## Documentation + +TODO + +## Tests + +TODO + diff --git a/samples/client/petstore/python/client/__init__.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/__init__.py similarity index 100% rename from samples/client/petstore/python/client/__init__.py rename to samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/__init__.py diff --git a/samples/client/petstore/python/client/models/__init__.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/__init__.py similarity index 100% rename from samples/client/petstore/python/client/models/__init__.py rename to samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/__init__.py diff --git a/samples/client/petstore/python/client/models/category.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/category.py similarity index 98% rename from samples/client/petstore/python/client/models/category.py rename to samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/category.py index 3d64348d1d..7b41a32a7d 100644 --- a/samples/client/petstore/python/client/models/category.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/category.py @@ -1,4 +1,6 @@ #!/usr/bin/env python +# coding: utf-8 + """ Copyright 2015 Reverb Technologies, Inc. @@ -41,7 +43,7 @@ class Category(object): 'name': 'name' - } + } diff --git a/samples/client/petstore/python/client/models/order.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/order.py similarity index 98% rename from samples/client/petstore/python/client/models/order.py rename to samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/order.py index 717773a729..84780db378 100644 --- a/samples/client/petstore/python/client/models/order.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/order.py @@ -1,4 +1,6 @@ #!/usr/bin/env python +# coding: utf-8 + """ Copyright 2015 Reverb Technologies, Inc. @@ -61,7 +63,7 @@ class Order(object): 'complete': 'complete' - } + } diff --git a/samples/client/petstore/python/client/models/pet.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/pet.py similarity index 98% rename from samples/client/petstore/python/client/models/pet.py rename to samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/pet.py index a7db312641..1415d6f853 100644 --- a/samples/client/petstore/python/client/models/pet.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/pet.py @@ -1,4 +1,6 @@ #!/usr/bin/env python +# coding: utf-8 + """ Copyright 2015 Reverb Technologies, Inc. @@ -61,7 +63,7 @@ class Pet(object): 'status': 'status' - } + } diff --git a/samples/client/petstore/python/client/models/tag.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/tag.py similarity index 98% rename from samples/client/petstore/python/client/models/tag.py rename to samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/tag.py index 5d4411799e..a6ed308342 100644 --- a/samples/client/petstore/python/client/models/tag.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/tag.py @@ -1,4 +1,6 @@ #!/usr/bin/env python +# coding: utf-8 + """ Copyright 2015 Reverb Technologies, Inc. @@ -41,7 +43,7 @@ class Tag(object): 'name': 'name' - } + } diff --git a/samples/client/petstore/python/client/models/user.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/user.py similarity index 98% rename from samples/client/petstore/python/client/models/user.py rename to samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/user.py index f798271fbf..8559b33120 100644 --- a/samples/client/petstore/python/client/models/user.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/models/user.py @@ -1,4 +1,6 @@ #!/usr/bin/env python +# coding: utf-8 + """ Copyright 2015 Reverb Technologies, Inc. @@ -71,7 +73,7 @@ class User(object): 'user_status': 'userStatus' - } + } diff --git a/samples/client/petstore/python/client/pet_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/pet_api.py similarity index 99% rename from samples/client/petstore/python/client/pet_api.py rename to samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/pet_api.py index f90f5bae7a..d0a85e4a69 100644 --- a/samples/client/petstore/python/client/pet_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/pet_api.py @@ -1,4 +1,6 @@ #!/usr/bin/env python +# coding: utf-8 + """ PetApi.py Copyright 2015 Reverb Technologies, Inc. diff --git a/samples/client/petstore/python/client/store_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/store_api.py similarity index 99% rename from samples/client/petstore/python/client/store_api.py rename to samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/store_api.py index bf0b4abfbd..a7befb9762 100644 --- a/samples/client/petstore/python/client/store_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/store_api.py @@ -1,4 +1,6 @@ #!/usr/bin/env python +# coding: utf-8 + """ StoreApi.py Copyright 2015 Reverb Technologies, Inc. diff --git a/samples/client/petstore/python/client/swagger.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py similarity index 99% rename from samples/client/petstore/python/client/swagger.py rename to samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py index d5e54666e0..018e92536c 100644 --- a/samples/client/petstore/python/client/swagger.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py @@ -1,4 +1,6 @@ #!/usr/bin/env python +# coding: utf-8 + """Swagger generic API client. This client handles the client- server communication, and is invariant across implementations. Specifics of the methods and models for each application are generated from the Swagger diff --git a/samples/client/petstore/python/client/user_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/user_api.py similarity index 99% rename from samples/client/petstore/python/client/user_api.py rename to samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/user_api.py index 5b54b57f5b..432df9bb12 100644 --- a/samples/client/petstore/python/client/user_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/user_api.py @@ -1,4 +1,6 @@ #!/usr/bin/env python +# coding: utf-8 + """ UserApi.py Copyright 2015 Reverb Technologies, Inc. diff --git a/samples/client/petstore/python/SwaggerPetstore-python/setup.py b/samples/client/petstore/python/SwaggerPetstore-python/setup.py new file mode 100644 index 0000000000..14d6a73b3b --- /dev/null +++ b/samples/client/petstore/python/SwaggerPetstore-python/setup.py @@ -0,0 +1,32 @@ +import sys +from setuptools import setup, find_packages + + + +# To install the library, open a Terminal shell, then run this +# file by typing: +# +# python setup.py install +# +# You need to have the setuptools module installed. +# Try reading the setuptools documentation: +# http://pypi.python.org/pypi/setuptools + +REQUIRES = [] + +setup( + name="SwaggerPetstore", + version="1.0.0", + description="Swagger Petstore", + author_email="apiteam@wordnik.com", + url="", + keywords=["Swagger", "Swagger Petstore"], + install_requires=REQUIRES, + packages=find_packages(), + include_package_data=True, + long_description="""\ + This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + """ +) + +