mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 19:33:55 +00:00
Merge pull request #619 from geekerzp/develop_2.0_python_package
Update Python codegen to support packaging via Setuptools
This commit is contained in:
commit
252cb18aeb
@ -7,7 +7,9 @@ import java.io.File;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig {
|
public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
String module = "client";
|
protected String module = "SwaggerPetstore";
|
||||||
|
protected String invokerPackage;
|
||||||
|
protected String eggPackage;
|
||||||
|
|
||||||
public CodegenType getTag() {
|
public CodegenType getTag() {
|
||||||
return CodegenType.CLIENT;
|
return CodegenType.CLIENT;
|
||||||
@ -23,13 +25,17 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
public PythonClientCodegen() {
|
public PythonClientCodegen() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
eggPackage = module + "-python";
|
||||||
|
invokerPackage = eggPackage + "/" + module;
|
||||||
|
|
||||||
outputFolder = "generated-code/python";
|
outputFolder = "generated-code/python";
|
||||||
modelTemplateFiles.put("model.mustache", ".py");
|
modelTemplateFiles.put("model.mustache", ".py");
|
||||||
apiTemplateFiles.put("api.mustache", ".py");
|
apiTemplateFiles.put("api.mustache", ".py");
|
||||||
templateDir = "python";
|
templateDir = "python";
|
||||||
|
|
||||||
apiPackage = module;
|
apiPackage = invokerPackage;
|
||||||
modelPackage = module + ".models";
|
modelPackage = invokerPackage + ".models";
|
||||||
|
|
||||||
languageSpecificPrimitives.clear();
|
languageSpecificPrimitives.clear();
|
||||||
languageSpecificPrimitives.add("int");
|
languageSpecificPrimitives.add("int");
|
||||||
@ -59,9 +65,12 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
"print", "class", "exec", "in", "raise", "continue", "finally", "is",
|
"print", "class", "exec", "in", "raise", "continue", "finally", "is",
|
||||||
"return", "def", "for", "lambda", "try"));
|
"return", "def", "for", "lambda", "try"));
|
||||||
|
|
||||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
additionalProperties.put("module", module);
|
||||||
supportingFiles.add(new SupportingFile("swagger.mustache", module, "swagger.py"));
|
|
||||||
supportingFiles.add(new SupportingFile("__init__package.mustache", module, "__init__.py"));
|
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"));
|
supportingFiles.add(new SupportingFile("__init__model.mustache", modelPackage.replace('.', File.separatorChar), "__init__.py"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
```python
|
||||||
# include the client module
|
import SwaggerPetstore
|
||||||
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}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|
||||||
|
@ -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}}
|
@ -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}
|
|
||||||
```
|
|
@ -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
|
||||||
|
|
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Copyright 2015 Reverb Technologies, Inc.
|
Copyright 2015 Reverb Technologies, Inc.
|
||||||
|
|
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Copyright 2015 Reverb Technologies, Inc.
|
Copyright 2015 Reverb Technologies, Inc.
|
||||||
|
|
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Copyright 2015 Reverb Technologies, Inc.
|
Copyright 2015 Reverb Technologies, Inc.
|
||||||
|
|
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Copyright 2015 Reverb Technologies, Inc.
|
Copyright 2015 Reverb Technologies, Inc.
|
||||||
|
|
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Copyright 2015 Reverb Technologies, Inc.
|
Copyright 2015 Reverb Technologies, Inc.
|
||||||
|
|
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
PetApi.py
|
PetApi.py
|
||||||
Copyright 2015 Reverb Technologies, Inc.
|
Copyright 2015 Reverb Technologies, Inc.
|
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
StoreApi.py
|
StoreApi.py
|
||||||
Copyright 2015 Reverb Technologies, Inc.
|
Copyright 2015 Reverb Technologies, Inc.
|
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
"""Swagger generic API client. This client handles the client-
|
"""Swagger generic API client. This client handles the client-
|
||||||
server communication, and is invariant across implementations. Specifics of
|
server communication, and is invariant across implementations. Specifics of
|
||||||
the methods and models for each application are generated from the Swagger
|
the methods and models for each application are generated from the Swagger
|
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
UserApi.py
|
UserApi.py
|
||||||
Copyright 2015 Reverb Technologies, Inc.
|
Copyright 2015 Reverb Technologies, Inc.
|
@ -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
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user