forked from loafle/openapi-generator-original
added readme, rebuilt client
This commit is contained in:
parent
719820c089
commit
e943f5c864
@ -26,6 +26,8 @@ cd $APP_DIR
|
||||
./bin/java-petstore-filemap.sh
|
||||
./bin/java-petstore.sh
|
||||
./bin/java-wordnik-api.sh
|
||||
./bin/php-petstore.sh
|
||||
./bin/python-petstore.sh
|
||||
./bin/objc-petstore.sh
|
||||
./bin/objc-wordnik-api.sh
|
||||
./bin/tizen-petstore.sh
|
||||
|
@ -31,6 +31,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ -i http://petstore.swagger.io/v2/swagger.json -l python -o samples/client/petstore/python -t modules/swagger-codegen/src/main/resources/python"
|
||||
ags="$@ -i http://petstore.swagger.io/v2/swagger.json -l python -o samples/client/petstore/python"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -62,6 +62,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
typeMapping.put("date", "datetime");
|
||||
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("swagger.mustache", module, "swagger.py"));
|
||||
supportingFiles.add(new SupportingFile("__init__.mustache", module, "__init__.py"));
|
||||
supportingFiles.add(new SupportingFile("__init__.mustache", modelPackage.replaceAll("\\.", File.separator), "__init__.py"));
|
||||
|
@ -0,0 +1,25 @@
|
||||
# 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}
|
||||
```
|
25
samples/client/petstore/python/README.md
Normal file
25
samples/client/petstore/python/README.md
Normal file
@ -0,0 +1,25 @@
|
||||
# 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}
|
||||
```
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
"""Wordnik.com's 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
|
||||
the methods and models for each application are generated from the Swagger
|
||||
templates."""
|
||||
@ -20,27 +20,31 @@ from models import *
|
||||
|
||||
|
||||
class ApiClient:
|
||||
"""Generic API client for Swagger client library builds"""
|
||||
"""Generic API client for Swagger client library builds
|
||||
|
||||
def __init__(self, apiKey=None, apiServer=None):
|
||||
if apiKey == None:
|
||||
raise Exception('You must pass an apiKey when instantiating the '
|
||||
'APIClient')
|
||||
self.apiKey = apiKey
|
||||
self.apiServer = apiServer
|
||||
Attributes:
|
||||
host: The base path for the server to call
|
||||
headerName: a header to pass when making calls to the API
|
||||
headerValue: a header value to pass when making calls to the API
|
||||
"""
|
||||
def __init__(self, host=None, headerName=None, headerValue=None):
|
||||
self.headerName = headerName
|
||||
self.headerValue = headerValue
|
||||
self.host = host
|
||||
self.cookie = None
|
||||
self.boundary = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(30))
|
||||
|
||||
def callAPI(self, resourcePath, method, queryParams, postData,
|
||||
headerParams=None, files=None):
|
||||
|
||||
url = self.apiServer + resourcePath
|
||||
url = self.host + resourcePath
|
||||
headers = {}
|
||||
if headerParams:
|
||||
for param, value in headerParams.iteritems():
|
||||
headers[param] = value
|
||||
|
||||
headers['api_key'] = self.apiKey
|
||||
if self.headerName:
|
||||
headers[self.headerName] = self.headerValue
|
||||
|
||||
if self.cookie:
|
||||
headers['Cookie'] = self.cookie
|
||||
@ -56,12 +60,10 @@ class ApiClient:
|
||||
url = url + '?' + urllib.urlencode(sentQueryParams)
|
||||
|
||||
if method in ['GET']:
|
||||
|
||||
#Options to add statements later on and for compatibility
|
||||
pass
|
||||
|
||||
elif method in ['POST', 'PUT', 'DELETE']:
|
||||
|
||||
if postData:
|
||||
postData = self.sanitizeForSerialization(postData)
|
||||
if 'Content-type' not in headers:
|
||||
@ -195,8 +197,7 @@ class ApiClient:
|
||||
# Server will always return a time stamp in UTC, but with
|
||||
# trailing +0000 indicating no offset from UTC. So don't process
|
||||
# last 5 characters.
|
||||
return datetime.datetime.strptime(obj[:-5],
|
||||
"%Y-%m-%dT%H:%M:%S.%f")
|
||||
return datetime.datetime.strptime(obj[:-5], "%Y-%m-%dT%H:%M:%S.%f")
|
||||
|
||||
instance = objClass()
|
||||
|
||||
@ -213,8 +214,7 @@ class ApiClient:
|
||||
value = value
|
||||
setattr(instance, attr, value)
|
||||
elif (attrType == 'datetime'):
|
||||
setattr(instance, attr, datetime.datetime.strptime(value[:-5],
|
||||
"%Y-%m-%dT%H:%M:%S.%f"))
|
||||
setattr(instance, attr, datetime.datetime.strptime(value[:-5], "%Y-%m-%dT%H:%M:%S.%f"))
|
||||
elif 'list[' in attrType:
|
||||
match = re.match('list\[(.*)\]', attrType)
|
||||
subClass = match.group(1)
|
||||
@ -223,18 +223,15 @@ class ApiClient:
|
||||
setattr(instance, attr, None)
|
||||
else:
|
||||
for subValue in value:
|
||||
subValues.append(self.deserialize(subValue,
|
||||
subClass))
|
||||
subValues.append(self.deserialize(subValue, subClass))
|
||||
setattr(instance, attr, subValues)
|
||||
else:
|
||||
setattr(instance, attr, self.deserialize(value,
|
||||
objClass))
|
||||
setattr(instance, attr, self.deserialize(value, objClass))
|
||||
|
||||
return instance
|
||||
|
||||
|
||||
class MethodRequest(urllib2.Request):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Construct a MethodRequest. Usage is the same as for
|
||||
`urllib2.Request` except it also takes an optional `method`
|
||||
@ -247,4 +244,3 @@ class MethodRequest(urllib2.Request):
|
||||
|
||||
def get_method(self):
|
||||
return getattr(self, 'method', urllib2.Request.get_method(self))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user