forked from loafle/openapi-generator-original
Merge pull request #4178 from cbornet/flask
[Flask] Add models support to Flask Connexion codegen
This commit is contained in:
@@ -10,7 +10,7 @@ This example uses the [Connexion](https://github.com/zalando/connexion) library
|
||||
To run the server, please execute the following:
|
||||
|
||||
```
|
||||
sudo pip install -U connexion # install Connexion from PyPI
|
||||
sudo pip install -U connexion typing # install Connexion and Typing from PyPI
|
||||
python app.py
|
||||
```
|
||||
|
||||
|
||||
@@ -1,8 +1,29 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import connexion
|
||||
from connexion.decorators import produces
|
||||
from six import iteritems
|
||||
from models.base_model_ import Model
|
||||
|
||||
|
||||
class JSONEncoder(produces.JSONEncoder):
|
||||
include_nulls = False
|
||||
|
||||
def default(self, o):
|
||||
if isinstance(o, Model):
|
||||
dikt = {}
|
||||
for attr, _ in iteritems(o.swagger_types):
|
||||
value = getattr(o, attr)
|
||||
if value is None and not self.include_nulls:
|
||||
continue
|
||||
attr = o.attribute_map[attr]
|
||||
dikt[attr] = value
|
||||
return dikt
|
||||
return produces.JSONEncoder.default(self, o)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = connexion.App(__name__, specification_dir='./swagger/')
|
||||
app.app.json_encoder = JSONEncoder
|
||||
app.add_api('swagger.yaml', arguments={'title': 'This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.'})
|
||||
app.run(port=8080)
|
||||
|
||||
@@ -1,24 +1,117 @@
|
||||
import connexion
|
||||
from models.pet import Pet
|
||||
from models.api_response import ApiResponse
|
||||
from datetime import date, datetime
|
||||
from typing import List, Dict
|
||||
from six import iteritems
|
||||
from util import deserialize_date, deserialize_datetime
|
||||
|
||||
|
||||
def add_pet(body):
|
||||
"""
|
||||
Add a new pet to the store
|
||||
|
||||
:param body: Pet object that needs to be added to the store
|
||||
:type body: dict | bytes
|
||||
|
||||
:rtype: None
|
||||
"""
|
||||
if connexion.request.is_json:
|
||||
body = Pet.from_dict(connexion.request.get_json())
|
||||
return 'do some magic!'
|
||||
|
||||
def delete_pet(petId, apiKey = None):
|
||||
|
||||
def delete_pet(petId, apiKey=None):
|
||||
"""
|
||||
Deletes a pet
|
||||
|
||||
:param petId: Pet id to delete
|
||||
:type petId: int
|
||||
:param apiKey:
|
||||
:type apiKey: str
|
||||
|
||||
:rtype: None
|
||||
"""
|
||||
return 'do some magic!'
|
||||
|
||||
|
||||
def find_pets_by_status(status):
|
||||
"""
|
||||
Finds Pets by status
|
||||
Multiple status values can be provided with comma separated strings
|
||||
:param status: Status values that need to be considered for filter
|
||||
:type status: List[str]
|
||||
|
||||
:rtype: List[Pet]
|
||||
"""
|
||||
return 'do some magic!'
|
||||
|
||||
|
||||
def find_pets_by_tags(tags):
|
||||
"""
|
||||
Finds Pets by tags
|
||||
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
:param tags: Tags to filter by
|
||||
:type tags: List[str]
|
||||
|
||||
:rtype: List[Pet]
|
||||
"""
|
||||
return 'do some magic!'
|
||||
|
||||
|
||||
def get_pet_by_id(petId):
|
||||
"""
|
||||
Find pet by ID
|
||||
Returns a single pet
|
||||
:param petId: ID of pet to return
|
||||
:type petId: int
|
||||
|
||||
:rtype: Pet
|
||||
"""
|
||||
return 'do some magic!'
|
||||
|
||||
|
||||
def update_pet(body):
|
||||
"""
|
||||
Update an existing pet
|
||||
|
||||
:param body: Pet object that needs to be added to the store
|
||||
:type body: dict | bytes
|
||||
|
||||
:rtype: None
|
||||
"""
|
||||
if connexion.request.is_json:
|
||||
body = Pet.from_dict(connexion.request.get_json())
|
||||
return 'do some magic!'
|
||||
|
||||
def update_pet_with_form(petId, name = None, status = None):
|
||||
|
||||
def update_pet_with_form(petId, name=None, status=None):
|
||||
"""
|
||||
Updates a pet in the store with form data
|
||||
|
||||
:param petId: ID of pet that needs to be updated
|
||||
:type petId: int
|
||||
:param name: Updated name of the pet
|
||||
:type name: str
|
||||
:param status: Updated status of the pet
|
||||
:type status: str
|
||||
|
||||
:rtype: None
|
||||
"""
|
||||
return 'do some magic!'
|
||||
|
||||
def upload_file(petId, additionalMetadata = None, file = None):
|
||||
|
||||
def upload_file(petId, additionalMetadata=None, file=None):
|
||||
"""
|
||||
uploads an image
|
||||
|
||||
:param petId: ID of pet to update
|
||||
:type petId: int
|
||||
:param additionalMetadata: Additional data to pass to server
|
||||
:type additionalMetadata: str
|
||||
:param file: file to upload
|
||||
:type file: werkzeug.datastructures.FileStorage
|
||||
|
||||
:rtype: ApiResponse
|
||||
"""
|
||||
return 'do some magic!'
|
||||
|
||||
@@ -1,12 +1,54 @@
|
||||
import connexion
|
||||
from models.order import Order
|
||||
from datetime import date, datetime
|
||||
from typing import List, Dict
|
||||
from six import iteritems
|
||||
from util import deserialize_date, deserialize_datetime
|
||||
|
||||
|
||||
def delete_order(orderId):
|
||||
"""
|
||||
Delete purchase order by ID
|
||||
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
:param orderId: ID of the order that needs to be deleted
|
||||
:type orderId: str
|
||||
|
||||
:rtype: None
|
||||
"""
|
||||
return 'do some magic!'
|
||||
|
||||
|
||||
def get_inventory():
|
||||
"""
|
||||
Returns pet inventories by status
|
||||
Returns a map of status codes to quantities
|
||||
|
||||
:rtype: Dict[str, int]
|
||||
"""
|
||||
return 'do some magic!'
|
||||
|
||||
|
||||
def get_order_by_id(orderId):
|
||||
"""
|
||||
Find purchase order by ID
|
||||
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
:param orderId: ID of pet that needs to be fetched
|
||||
:type orderId: int
|
||||
|
||||
:rtype: Order
|
||||
"""
|
||||
return 'do some magic!'
|
||||
|
||||
|
||||
def place_order(body):
|
||||
"""
|
||||
Place an order for a pet
|
||||
|
||||
:param body: order placed for purchasing the pet
|
||||
:type body: dict | bytes
|
||||
|
||||
:rtype: Order
|
||||
"""
|
||||
if connexion.request.is_json:
|
||||
body = Order.from_dict(connexion.request.get_json())
|
||||
return 'do some magic!'
|
||||
|
||||
@@ -1,24 +1,112 @@
|
||||
import connexion
|
||||
from models.user import User
|
||||
from datetime import date, datetime
|
||||
from typing import List, Dict
|
||||
from six import iteritems
|
||||
from util import deserialize_date, deserialize_datetime
|
||||
|
||||
|
||||
def create_user(body):
|
||||
"""
|
||||
Create user
|
||||
This can only be done by the logged in user.
|
||||
:param body: Created user object
|
||||
:type body: dict | bytes
|
||||
|
||||
:rtype: None
|
||||
"""
|
||||
if connexion.request.is_json:
|
||||
body = User.from_dict(connexion.request.get_json())
|
||||
return 'do some magic!'
|
||||
|
||||
|
||||
def create_users_with_array_input(body):
|
||||
"""
|
||||
Creates list of users with given input array
|
||||
|
||||
:param body: List of user object
|
||||
:type body: list | bytes
|
||||
|
||||
:rtype: None
|
||||
"""
|
||||
if connexion.request.is_json:
|
||||
body = [User.from_dict(d) for d in connexion.request.get_json()]
|
||||
return 'do some magic!'
|
||||
|
||||
|
||||
def create_users_with_list_input(body):
|
||||
"""
|
||||
Creates list of users with given input array
|
||||
|
||||
:param body: List of user object
|
||||
:type body: list | bytes
|
||||
|
||||
:rtype: None
|
||||
"""
|
||||
if connexion.request.is_json:
|
||||
body = [User.from_dict(d) for d in connexion.request.get_json()]
|
||||
return 'do some magic!'
|
||||
|
||||
|
||||
def delete_user(username):
|
||||
"""
|
||||
Delete user
|
||||
This can only be done by the logged in user.
|
||||
:param username: The name that needs to be deleted
|
||||
:type username: str
|
||||
|
||||
:rtype: None
|
||||
"""
|
||||
return 'do some magic!'
|
||||
|
||||
|
||||
def get_user_by_name(username):
|
||||
"""
|
||||
Get user by user name
|
||||
|
||||
:param username: The name that needs to be fetched. Use user1 for testing.
|
||||
:type username: str
|
||||
|
||||
:rtype: User
|
||||
"""
|
||||
return 'do some magic!'
|
||||
|
||||
|
||||
def login_user(username, password):
|
||||
"""
|
||||
Logs user into the system
|
||||
|
||||
:param username: The user name for login
|
||||
:type username: str
|
||||
:param password: The password for login in clear text
|
||||
:type password: str
|
||||
|
||||
:rtype: str
|
||||
"""
|
||||
return 'do some magic!'
|
||||
|
||||
|
||||
def logout_user():
|
||||
"""
|
||||
Logs out current logged in user session
|
||||
|
||||
|
||||
:rtype: None
|
||||
"""
|
||||
return 'do some magic!'
|
||||
|
||||
|
||||
def update_user(username, body):
|
||||
"""
|
||||
Updated user
|
||||
This can only be done by the logged in user.
|
||||
:param username: name that need to be deleted
|
||||
:type username: str
|
||||
:param body: Updated user object
|
||||
:type body: dict | bytes
|
||||
|
||||
:rtype: None
|
||||
"""
|
||||
if connexion.request.is_json:
|
||||
body = User.from_dict(connexion.request.get_json())
|
||||
return 'do some magic!'
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# coding: utf-8
|
||||
|
||||
from __future__ import absolute_import
|
||||
# import models into model package
|
||||
from .api_response import ApiResponse
|
||||
from .category import Category
|
||||
from .order import Order
|
||||
from .pet import Pet
|
||||
from .tag import Tag
|
||||
from .user import User
|
||||
@@ -0,0 +1,116 @@
|
||||
# coding: utf-8
|
||||
|
||||
from __future__ import absolute_import
|
||||
from .base_model_ import Model
|
||||
from datetime import date, datetime
|
||||
from typing import List, Dict
|
||||
from util import deserialize_model
|
||||
|
||||
|
||||
class ApiResponse(Model):
|
||||
"""
|
||||
NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
def __init__(self, code=None, type=None, message=None):
|
||||
"""
|
||||
ApiResponse - a model defined in Swagger
|
||||
|
||||
:param code: The code of this ApiResponse.
|
||||
:type code: int
|
||||
:param type: The type of this ApiResponse.
|
||||
:type type: str
|
||||
:param message: The message of this ApiResponse.
|
||||
:type message: str
|
||||
"""
|
||||
self.swagger_types = {
|
||||
'code': int,
|
||||
'type': str,
|
||||
'message': str
|
||||
}
|
||||
|
||||
self.attribute_map = {
|
||||
'code': 'code',
|
||||
'type': 'type',
|
||||
'message': 'message'
|
||||
}
|
||||
|
||||
self._code = code
|
||||
self._type = type
|
||||
self._message = message
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, dikt):
|
||||
"""
|
||||
Returns the dict as a model
|
||||
|
||||
:param dikt: A dict.
|
||||
:type: dict
|
||||
:return: The ApiResponse of this ApiResponse.
|
||||
:rtype: ApiResponse
|
||||
"""
|
||||
return deserialize_model(dikt, cls)
|
||||
|
||||
@property
|
||||
def code(self):
|
||||
"""
|
||||
Gets the code of this ApiResponse.
|
||||
|
||||
:return: The code of this ApiResponse.
|
||||
:rtype: int
|
||||
"""
|
||||
return self._code
|
||||
|
||||
@code.setter
|
||||
def code(self, code):
|
||||
"""
|
||||
Sets the code of this ApiResponse.
|
||||
|
||||
:param code: The code of this ApiResponse.
|
||||
:type code: int
|
||||
"""
|
||||
|
||||
self._code = code
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
"""
|
||||
Gets the type of this ApiResponse.
|
||||
|
||||
:return: The type of this ApiResponse.
|
||||
:rtype: str
|
||||
"""
|
||||
return self._type
|
||||
|
||||
@type.setter
|
||||
def type(self, type):
|
||||
"""
|
||||
Sets the type of this ApiResponse.
|
||||
|
||||
:param type: The type of this ApiResponse.
|
||||
:type type: str
|
||||
"""
|
||||
|
||||
self._type = type
|
||||
|
||||
@property
|
||||
def message(self):
|
||||
"""
|
||||
Gets the message of this ApiResponse.
|
||||
|
||||
:return: The message of this ApiResponse.
|
||||
:rtype: str
|
||||
"""
|
||||
return self._message
|
||||
|
||||
@message.setter
|
||||
def message(self, message):
|
||||
"""
|
||||
Sets the message of this ApiResponse.
|
||||
|
||||
:param message: The message of this ApiResponse.
|
||||
:type message: str
|
||||
"""
|
||||
|
||||
self._message = message
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
from pprint import pformat
|
||||
from six import iteritems
|
||||
from util import deserialize_model
|
||||
|
||||
|
||||
class Model(object):
|
||||
# swaggerTypes: The key is attribute name and the value is attribute type.
|
||||
swagger_types = {}
|
||||
|
||||
# attributeMap: The key is attribute name and the value is json key in definition.
|
||||
attribute_map = {}
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, dikt):
|
||||
"""
|
||||
Returns the dict as a model
|
||||
"""
|
||||
return deserialize_model(dikt, cls)
|
||||
|
||||
def to_dict(self):
|
||||
"""
|
||||
Returns the model properties as a dict
|
||||
|
||||
:rtype: dict
|
||||
"""
|
||||
result = {}
|
||||
|
||||
for attr, _ in iteritems(self.swagger_types):
|
||||
value = getattr(self, attr)
|
||||
if isinstance(value, list):
|
||||
result[attr] = list(map(
|
||||
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
|
||||
value
|
||||
))
|
||||
elif hasattr(value, "to_dict"):
|
||||
result[attr] = value.to_dict()
|
||||
elif isinstance(value, dict):
|
||||
result[attr] = dict(map(
|
||||
lambda item: (item[0], item[1].to_dict())
|
||||
if hasattr(item[1], "to_dict") else item,
|
||||
value.items()
|
||||
))
|
||||
else:
|
||||
result[attr] = value
|
||||
|
||||
return result
|
||||
|
||||
def to_str(self):
|
||||
"""
|
||||
Returns the string representation of the model
|
||||
|
||||
:rtype: str
|
||||
"""
|
||||
return pformat(self.to_dict())
|
||||
|
||||
def __repr__(self):
|
||||
"""
|
||||
For `print` and `pprint`
|
||||
"""
|
||||
return self.to_str()
|
||||
|
||||
def __eq__(self, other):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
"""
|
||||
Returns true if both objects are not equal
|
||||
"""
|
||||
return not self == other
|
||||
@@ -0,0 +1,90 @@
|
||||
# coding: utf-8
|
||||
|
||||
from __future__ import absolute_import
|
||||
from .base_model_ import Model
|
||||
from datetime import date, datetime
|
||||
from typing import List, Dict
|
||||
from util import deserialize_model
|
||||
|
||||
|
||||
class Category(Model):
|
||||
"""
|
||||
NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
def __init__(self, id=None, name=None):
|
||||
"""
|
||||
Category - a model defined in Swagger
|
||||
|
||||
:param id: The id of this Category.
|
||||
:type id: int
|
||||
:param name: The name of this Category.
|
||||
:type name: str
|
||||
"""
|
||||
self.swagger_types = {
|
||||
'id': int,
|
||||
'name': str
|
||||
}
|
||||
|
||||
self.attribute_map = {
|
||||
'id': 'id',
|
||||
'name': 'name'
|
||||
}
|
||||
|
||||
self._id = id
|
||||
self._name = name
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, dikt):
|
||||
"""
|
||||
Returns the dict as a model
|
||||
|
||||
:param dikt: A dict.
|
||||
:type: dict
|
||||
:return: The Category of this Category.
|
||||
:rtype: Category
|
||||
"""
|
||||
return deserialize_model(dikt, cls)
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""
|
||||
Gets the id of this Category.
|
||||
|
||||
:return: The id of this Category.
|
||||
:rtype: int
|
||||
"""
|
||||
return self._id
|
||||
|
||||
@id.setter
|
||||
def id(self, id):
|
||||
"""
|
||||
Sets the id of this Category.
|
||||
|
||||
:param id: The id of this Category.
|
||||
:type id: int
|
||||
"""
|
||||
|
||||
self._id = id
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
Gets the name of this Category.
|
||||
|
||||
:return: The name of this Category.
|
||||
:rtype: str
|
||||
"""
|
||||
return self._name
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
"""
|
||||
Sets the name of this Category.
|
||||
|
||||
:param name: The name of this Category.
|
||||
:type name: str
|
||||
"""
|
||||
|
||||
self._name = name
|
||||
|
||||
202
samples/server/petstore/flaskConnexion-python2/models/order.py
Normal file
202
samples/server/petstore/flaskConnexion-python2/models/order.py
Normal file
@@ -0,0 +1,202 @@
|
||||
# coding: utf-8
|
||||
|
||||
from __future__ import absolute_import
|
||||
from .base_model_ import Model
|
||||
from datetime import date, datetime
|
||||
from typing import List, Dict
|
||||
from util import deserialize_model
|
||||
|
||||
|
||||
class Order(Model):
|
||||
"""
|
||||
NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
def __init__(self, id=None, pet_id=None, quantity=None, ship_date=None, status=None, complete=False):
|
||||
"""
|
||||
Order - a model defined in Swagger
|
||||
|
||||
:param id: The id of this Order.
|
||||
:type id: int
|
||||
:param pet_id: The pet_id of this Order.
|
||||
:type pet_id: int
|
||||
:param quantity: The quantity of this Order.
|
||||
:type quantity: int
|
||||
:param ship_date: The ship_date of this Order.
|
||||
:type ship_date: datetime
|
||||
:param status: The status of this Order.
|
||||
:type status: str
|
||||
:param complete: The complete of this Order.
|
||||
:type complete: bool
|
||||
"""
|
||||
self.swagger_types = {
|
||||
'id': int,
|
||||
'pet_id': int,
|
||||
'quantity': int,
|
||||
'ship_date': datetime,
|
||||
'status': str,
|
||||
'complete': bool
|
||||
}
|
||||
|
||||
self.attribute_map = {
|
||||
'id': 'id',
|
||||
'pet_id': 'petId',
|
||||
'quantity': 'quantity',
|
||||
'ship_date': 'shipDate',
|
||||
'status': 'status',
|
||||
'complete': 'complete'
|
||||
}
|
||||
|
||||
self._id = id
|
||||
self._pet_id = pet_id
|
||||
self._quantity = quantity
|
||||
self._ship_date = ship_date
|
||||
self._status = status
|
||||
self._complete = complete
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, dikt):
|
||||
"""
|
||||
Returns the dict as a model
|
||||
|
||||
:param dikt: A dict.
|
||||
:type: dict
|
||||
:return: The Order of this Order.
|
||||
:rtype: Order
|
||||
"""
|
||||
return deserialize_model(dikt, cls)
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""
|
||||
Gets the id of this Order.
|
||||
|
||||
:return: The id of this Order.
|
||||
:rtype: int
|
||||
"""
|
||||
return self._id
|
||||
|
||||
@id.setter
|
||||
def id(self, id):
|
||||
"""
|
||||
Sets the id of this Order.
|
||||
|
||||
:param id: The id of this Order.
|
||||
:type id: int
|
||||
"""
|
||||
|
||||
self._id = id
|
||||
|
||||
@property
|
||||
def pet_id(self):
|
||||
"""
|
||||
Gets the pet_id of this Order.
|
||||
|
||||
:return: The pet_id of this Order.
|
||||
:rtype: int
|
||||
"""
|
||||
return self._pet_id
|
||||
|
||||
@pet_id.setter
|
||||
def pet_id(self, pet_id):
|
||||
"""
|
||||
Sets the pet_id of this Order.
|
||||
|
||||
:param pet_id: The pet_id of this Order.
|
||||
:type pet_id: int
|
||||
"""
|
||||
|
||||
self._pet_id = pet_id
|
||||
|
||||
@property
|
||||
def quantity(self):
|
||||
"""
|
||||
Gets the quantity of this Order.
|
||||
|
||||
:return: The quantity of this Order.
|
||||
:rtype: int
|
||||
"""
|
||||
return self._quantity
|
||||
|
||||
@quantity.setter
|
||||
def quantity(self, quantity):
|
||||
"""
|
||||
Sets the quantity of this Order.
|
||||
|
||||
:param quantity: The quantity of this Order.
|
||||
:type quantity: int
|
||||
"""
|
||||
|
||||
self._quantity = quantity
|
||||
|
||||
@property
|
||||
def ship_date(self):
|
||||
"""
|
||||
Gets the ship_date of this Order.
|
||||
|
||||
:return: The ship_date of this Order.
|
||||
:rtype: datetime
|
||||
"""
|
||||
return self._ship_date
|
||||
|
||||
@ship_date.setter
|
||||
def ship_date(self, ship_date):
|
||||
"""
|
||||
Sets the ship_date of this Order.
|
||||
|
||||
:param ship_date: The ship_date of this Order.
|
||||
:type ship_date: datetime
|
||||
"""
|
||||
|
||||
self._ship_date = ship_date
|
||||
|
||||
@property
|
||||
def status(self):
|
||||
"""
|
||||
Gets the status of this Order.
|
||||
Order Status
|
||||
|
||||
:return: The status of this Order.
|
||||
:rtype: str
|
||||
"""
|
||||
return self._status
|
||||
|
||||
@status.setter
|
||||
def status(self, status):
|
||||
"""
|
||||
Sets the status of this Order.
|
||||
Order Status
|
||||
|
||||
:param status: The status of this Order.
|
||||
:type status: str
|
||||
"""
|
||||
allowed_values = ["placed", "approved", "delivered"]
|
||||
if status not in allowed_values:
|
||||
raise ValueError(
|
||||
"Invalid value for `status` ({0}), must be one of {1}"
|
||||
.format(status, allowed_values)
|
||||
)
|
||||
|
||||
self._status = status
|
||||
|
||||
@property
|
||||
def complete(self):
|
||||
"""
|
||||
Gets the complete of this Order.
|
||||
|
||||
:return: The complete of this Order.
|
||||
:rtype: bool
|
||||
"""
|
||||
return self._complete
|
||||
|
||||
@complete.setter
|
||||
def complete(self, complete):
|
||||
"""
|
||||
Sets the complete of this Order.
|
||||
|
||||
:param complete: The complete of this Order.
|
||||
:type complete: bool
|
||||
"""
|
||||
|
||||
self._complete = complete
|
||||
|
||||
208
samples/server/petstore/flaskConnexion-python2/models/pet.py
Normal file
208
samples/server/petstore/flaskConnexion-python2/models/pet.py
Normal file
@@ -0,0 +1,208 @@
|
||||
# coding: utf-8
|
||||
|
||||
from __future__ import absolute_import
|
||||
from models.category import Category
|
||||
from models.tag import Tag
|
||||
from .base_model_ import Model
|
||||
from datetime import date, datetime
|
||||
from typing import List, Dict
|
||||
from util import deserialize_model
|
||||
|
||||
|
||||
class Pet(Model):
|
||||
"""
|
||||
NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
def __init__(self, id=None, category=None, name=None, photo_urls=None, tags=None, status=None):
|
||||
"""
|
||||
Pet - a model defined in Swagger
|
||||
|
||||
:param id: The id of this Pet.
|
||||
:type id: int
|
||||
:param category: The category of this Pet.
|
||||
:type category: Category
|
||||
:param name: The name of this Pet.
|
||||
:type name: str
|
||||
:param photo_urls: The photo_urls of this Pet.
|
||||
:type photo_urls: List[str]
|
||||
:param tags: The tags of this Pet.
|
||||
:type tags: List[Tag]
|
||||
:param status: The status of this Pet.
|
||||
:type status: str
|
||||
"""
|
||||
self.swagger_types = {
|
||||
'id': int,
|
||||
'category': Category,
|
||||
'name': str,
|
||||
'photo_urls': List[str],
|
||||
'tags': List[Tag],
|
||||
'status': str
|
||||
}
|
||||
|
||||
self.attribute_map = {
|
||||
'id': 'id',
|
||||
'category': 'category',
|
||||
'name': 'name',
|
||||
'photo_urls': 'photoUrls',
|
||||
'tags': 'tags',
|
||||
'status': 'status'
|
||||
}
|
||||
|
||||
self._id = id
|
||||
self._category = category
|
||||
self._name = name
|
||||
self._photo_urls = photo_urls
|
||||
self._tags = tags
|
||||
self._status = status
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, dikt):
|
||||
"""
|
||||
Returns the dict as a model
|
||||
|
||||
:param dikt: A dict.
|
||||
:type: dict
|
||||
:return: The Pet of this Pet.
|
||||
:rtype: Pet
|
||||
"""
|
||||
return deserialize_model(dikt, cls)
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""
|
||||
Gets the id of this Pet.
|
||||
|
||||
:return: The id of this Pet.
|
||||
:rtype: int
|
||||
"""
|
||||
return self._id
|
||||
|
||||
@id.setter
|
||||
def id(self, id):
|
||||
"""
|
||||
Sets the id of this Pet.
|
||||
|
||||
:param id: The id of this Pet.
|
||||
:type id: int
|
||||
"""
|
||||
|
||||
self._id = id
|
||||
|
||||
@property
|
||||
def category(self):
|
||||
"""
|
||||
Gets the category of this Pet.
|
||||
|
||||
:return: The category of this Pet.
|
||||
:rtype: Category
|
||||
"""
|
||||
return self._category
|
||||
|
||||
@category.setter
|
||||
def category(self, category):
|
||||
"""
|
||||
Sets the category of this Pet.
|
||||
|
||||
:param category: The category of this Pet.
|
||||
:type category: Category
|
||||
"""
|
||||
|
||||
self._category = category
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
Gets the name of this Pet.
|
||||
|
||||
:return: The name of this Pet.
|
||||
:rtype: str
|
||||
"""
|
||||
return self._name
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
"""
|
||||
Sets the name of this Pet.
|
||||
|
||||
:param name: The name of this Pet.
|
||||
:type name: str
|
||||
"""
|
||||
if name is None:
|
||||
raise ValueError("Invalid value for `name`, must not be `None`")
|
||||
|
||||
self._name = name
|
||||
|
||||
@property
|
||||
def photo_urls(self):
|
||||
"""
|
||||
Gets the photo_urls of this Pet.
|
||||
|
||||
:return: The photo_urls of this Pet.
|
||||
:rtype: List[str]
|
||||
"""
|
||||
return self._photo_urls
|
||||
|
||||
@photo_urls.setter
|
||||
def photo_urls(self, photo_urls):
|
||||
"""
|
||||
Sets the photo_urls of this Pet.
|
||||
|
||||
:param photo_urls: The photo_urls of this Pet.
|
||||
:type photo_urls: List[str]
|
||||
"""
|
||||
if photo_urls is None:
|
||||
raise ValueError("Invalid value for `photo_urls`, must not be `None`")
|
||||
|
||||
self._photo_urls = photo_urls
|
||||
|
||||
@property
|
||||
def tags(self):
|
||||
"""
|
||||
Gets the tags of this Pet.
|
||||
|
||||
:return: The tags of this Pet.
|
||||
:rtype: List[Tag]
|
||||
"""
|
||||
return self._tags
|
||||
|
||||
@tags.setter
|
||||
def tags(self, tags):
|
||||
"""
|
||||
Sets the tags of this Pet.
|
||||
|
||||
:param tags: The tags of this Pet.
|
||||
:type tags: List[Tag]
|
||||
"""
|
||||
|
||||
self._tags = tags
|
||||
|
||||
@property
|
||||
def status(self):
|
||||
"""
|
||||
Gets the status of this Pet.
|
||||
pet status in the store
|
||||
|
||||
:return: The status of this Pet.
|
||||
:rtype: str
|
||||
"""
|
||||
return self._status
|
||||
|
||||
@status.setter
|
||||
def status(self, status):
|
||||
"""
|
||||
Sets the status of this Pet.
|
||||
pet status in the store
|
||||
|
||||
:param status: The status of this Pet.
|
||||
:type status: str
|
||||
"""
|
||||
allowed_values = ["available", "pending", "sold"]
|
||||
if status not in allowed_values:
|
||||
raise ValueError(
|
||||
"Invalid value for `status` ({0}), must be one of {1}"
|
||||
.format(status, allowed_values)
|
||||
)
|
||||
|
||||
self._status = status
|
||||
|
||||
90
samples/server/petstore/flaskConnexion-python2/models/tag.py
Normal file
90
samples/server/petstore/flaskConnexion-python2/models/tag.py
Normal file
@@ -0,0 +1,90 @@
|
||||
# coding: utf-8
|
||||
|
||||
from __future__ import absolute_import
|
||||
from .base_model_ import Model
|
||||
from datetime import date, datetime
|
||||
from typing import List, Dict
|
||||
from util import deserialize_model
|
||||
|
||||
|
||||
class Tag(Model):
|
||||
"""
|
||||
NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
def __init__(self, id=None, name=None):
|
||||
"""
|
||||
Tag - a model defined in Swagger
|
||||
|
||||
:param id: The id of this Tag.
|
||||
:type id: int
|
||||
:param name: The name of this Tag.
|
||||
:type name: str
|
||||
"""
|
||||
self.swagger_types = {
|
||||
'id': int,
|
||||
'name': str
|
||||
}
|
||||
|
||||
self.attribute_map = {
|
||||
'id': 'id',
|
||||
'name': 'name'
|
||||
}
|
||||
|
||||
self._id = id
|
||||
self._name = name
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, dikt):
|
||||
"""
|
||||
Returns the dict as a model
|
||||
|
||||
:param dikt: A dict.
|
||||
:type: dict
|
||||
:return: The Tag of this Tag.
|
||||
:rtype: Tag
|
||||
"""
|
||||
return deserialize_model(dikt, cls)
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""
|
||||
Gets the id of this Tag.
|
||||
|
||||
:return: The id of this Tag.
|
||||
:rtype: int
|
||||
"""
|
||||
return self._id
|
||||
|
||||
@id.setter
|
||||
def id(self, id):
|
||||
"""
|
||||
Sets the id of this Tag.
|
||||
|
||||
:param id: The id of this Tag.
|
||||
:type id: int
|
||||
"""
|
||||
|
||||
self._id = id
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
Gets the name of this Tag.
|
||||
|
||||
:return: The name of this Tag.
|
||||
:rtype: str
|
||||
"""
|
||||
return self._name
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
"""
|
||||
Sets the name of this Tag.
|
||||
|
||||
:param name: The name of this Tag.
|
||||
:type name: str
|
||||
"""
|
||||
|
||||
self._name = name
|
||||
|
||||
248
samples/server/petstore/flaskConnexion-python2/models/user.py
Normal file
248
samples/server/petstore/flaskConnexion-python2/models/user.py
Normal file
@@ -0,0 +1,248 @@
|
||||
# coding: utf-8
|
||||
|
||||
from __future__ import absolute_import
|
||||
from .base_model_ import Model
|
||||
from datetime import date, datetime
|
||||
from typing import List, Dict
|
||||
from util import deserialize_model
|
||||
|
||||
|
||||
class User(Model):
|
||||
"""
|
||||
NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
def __init__(self, id=None, username=None, first_name=None, last_name=None, email=None, password=None, phone=None, user_status=None):
|
||||
"""
|
||||
User - a model defined in Swagger
|
||||
|
||||
:param id: The id of this User.
|
||||
:type id: int
|
||||
:param username: The username of this User.
|
||||
:type username: str
|
||||
:param first_name: The first_name of this User.
|
||||
:type first_name: str
|
||||
:param last_name: The last_name of this User.
|
||||
:type last_name: str
|
||||
:param email: The email of this User.
|
||||
:type email: str
|
||||
:param password: The password of this User.
|
||||
:type password: str
|
||||
:param phone: The phone of this User.
|
||||
:type phone: str
|
||||
:param user_status: The user_status of this User.
|
||||
:type user_status: int
|
||||
"""
|
||||
self.swagger_types = {
|
||||
'id': int,
|
||||
'username': str,
|
||||
'first_name': str,
|
||||
'last_name': str,
|
||||
'email': str,
|
||||
'password': str,
|
||||
'phone': str,
|
||||
'user_status': int
|
||||
}
|
||||
|
||||
self.attribute_map = {
|
||||
'id': 'id',
|
||||
'username': 'username',
|
||||
'first_name': 'firstName',
|
||||
'last_name': 'lastName',
|
||||
'email': 'email',
|
||||
'password': 'password',
|
||||
'phone': 'phone',
|
||||
'user_status': 'userStatus'
|
||||
}
|
||||
|
||||
self._id = id
|
||||
self._username = username
|
||||
self._first_name = first_name
|
||||
self._last_name = last_name
|
||||
self._email = email
|
||||
self._password = password
|
||||
self._phone = phone
|
||||
self._user_status = user_status
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, dikt):
|
||||
"""
|
||||
Returns the dict as a model
|
||||
|
||||
:param dikt: A dict.
|
||||
:type: dict
|
||||
:return: The User of this User.
|
||||
:rtype: User
|
||||
"""
|
||||
return deserialize_model(dikt, cls)
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""
|
||||
Gets the id of this User.
|
||||
|
||||
:return: The id of this User.
|
||||
:rtype: int
|
||||
"""
|
||||
return self._id
|
||||
|
||||
@id.setter
|
||||
def id(self, id):
|
||||
"""
|
||||
Sets the id of this User.
|
||||
|
||||
:param id: The id of this User.
|
||||
:type id: int
|
||||
"""
|
||||
|
||||
self._id = id
|
||||
|
||||
@property
|
||||
def username(self):
|
||||
"""
|
||||
Gets the username of this User.
|
||||
|
||||
:return: The username of this User.
|
||||
:rtype: str
|
||||
"""
|
||||
return self._username
|
||||
|
||||
@username.setter
|
||||
def username(self, username):
|
||||
"""
|
||||
Sets the username of this User.
|
||||
|
||||
:param username: The username of this User.
|
||||
:type username: str
|
||||
"""
|
||||
|
||||
self._username = username
|
||||
|
||||
@property
|
||||
def first_name(self):
|
||||
"""
|
||||
Gets the first_name of this User.
|
||||
|
||||
:return: The first_name of this User.
|
||||
:rtype: str
|
||||
"""
|
||||
return self._first_name
|
||||
|
||||
@first_name.setter
|
||||
def first_name(self, first_name):
|
||||
"""
|
||||
Sets the first_name of this User.
|
||||
|
||||
:param first_name: The first_name of this User.
|
||||
:type first_name: str
|
||||
"""
|
||||
|
||||
self._first_name = first_name
|
||||
|
||||
@property
|
||||
def last_name(self):
|
||||
"""
|
||||
Gets the last_name of this User.
|
||||
|
||||
:return: The last_name of this User.
|
||||
:rtype: str
|
||||
"""
|
||||
return self._last_name
|
||||
|
||||
@last_name.setter
|
||||
def last_name(self, last_name):
|
||||
"""
|
||||
Sets the last_name of this User.
|
||||
|
||||
:param last_name: The last_name of this User.
|
||||
:type last_name: str
|
||||
"""
|
||||
|
||||
self._last_name = last_name
|
||||
|
||||
@property
|
||||
def email(self):
|
||||
"""
|
||||
Gets the email of this User.
|
||||
|
||||
:return: The email of this User.
|
||||
:rtype: str
|
||||
"""
|
||||
return self._email
|
||||
|
||||
@email.setter
|
||||
def email(self, email):
|
||||
"""
|
||||
Sets the email of this User.
|
||||
|
||||
:param email: The email of this User.
|
||||
:type email: str
|
||||
"""
|
||||
|
||||
self._email = email
|
||||
|
||||
@property
|
||||
def password(self):
|
||||
"""
|
||||
Gets the password of this User.
|
||||
|
||||
:return: The password of this User.
|
||||
:rtype: str
|
||||
"""
|
||||
return self._password
|
||||
|
||||
@password.setter
|
||||
def password(self, password):
|
||||
"""
|
||||
Sets the password of this User.
|
||||
|
||||
:param password: The password of this User.
|
||||
:type password: str
|
||||
"""
|
||||
|
||||
self._password = password
|
||||
|
||||
@property
|
||||
def phone(self):
|
||||
"""
|
||||
Gets the phone of this User.
|
||||
|
||||
:return: The phone of this User.
|
||||
:rtype: str
|
||||
"""
|
||||
return self._phone
|
||||
|
||||
@phone.setter
|
||||
def phone(self, phone):
|
||||
"""
|
||||
Sets the phone of this User.
|
||||
|
||||
:param phone: The phone of this User.
|
||||
:type phone: str
|
||||
"""
|
||||
|
||||
self._phone = phone
|
||||
|
||||
@property
|
||||
def user_status(self):
|
||||
"""
|
||||
Gets the user_status of this User.
|
||||
User Status
|
||||
|
||||
:return: The user_status of this User.
|
||||
:rtype: int
|
||||
"""
|
||||
return self._user_status
|
||||
|
||||
@user_status.setter
|
||||
def user_status(self, user_status):
|
||||
"""
|
||||
Sets the user_status of this User.
|
||||
User Status
|
||||
|
||||
:param user_status: The user_status of this User.
|
||||
:type user_status: int
|
||||
"""
|
||||
|
||||
self._user_status = user_status
|
||||
|
||||
@@ -110,11 +110,11 @@ paths:
|
||||
type: "array"
|
||||
items:
|
||||
type: "string"
|
||||
default: "available"
|
||||
enum:
|
||||
- "available"
|
||||
- "pending"
|
||||
- "sold"
|
||||
default: "available"
|
||||
collectionFormat: "csv"
|
||||
responses:
|
||||
200:
|
||||
@@ -607,10 +607,6 @@ paths:
|
||||
x-tags:
|
||||
- tag: "user"
|
||||
securityDefinitions:
|
||||
api_key:
|
||||
type: "apiKey"
|
||||
name: "api_key"
|
||||
in: "header"
|
||||
petstore_auth:
|
||||
type: "oauth2"
|
||||
authorizationUrl: "http://petstore.swagger.io/api/oauth/dialog"
|
||||
@@ -618,6 +614,10 @@ securityDefinitions:
|
||||
scopes:
|
||||
write:pets: "modify pets in your account"
|
||||
read:pets: "read your pets"
|
||||
api_key:
|
||||
type: "apiKey"
|
||||
name: "api_key"
|
||||
in: "header"
|
||||
definitions:
|
||||
Order:
|
||||
type: "object"
|
||||
|
||||
149
samples/server/petstore/flaskConnexion-python2/util.py
Normal file
149
samples/server/petstore/flaskConnexion-python2/util.py
Normal file
@@ -0,0 +1,149 @@
|
||||
from typing import GenericMeta
|
||||
from datetime import datetime, date
|
||||
from six import integer_types, iteritems
|
||||
|
||||
|
||||
def _deserialize(data, klass):
|
||||
"""
|
||||
Deserializes dict, list, str into an object.
|
||||
|
||||
:param data: dict, list or str.
|
||||
:param klass: class literal, or string of class name.
|
||||
|
||||
:return: object.
|
||||
"""
|
||||
if data is None:
|
||||
return None
|
||||
|
||||
if klass in integer_types or klass in (float, str, bool):
|
||||
return _deserialize_primitive(data, klass)
|
||||
elif klass == object:
|
||||
return _deserialize_object(data)
|
||||
elif klass == date:
|
||||
return deserialize_date(data)
|
||||
elif klass == datetime:
|
||||
return deserialize_datetime(data)
|
||||
elif type(klass) == GenericMeta:
|
||||
if klass.__extra__ == list:
|
||||
return _deserialize_list(data, klass.__args__[0])
|
||||
if klass.__extra__ == dict:
|
||||
return _deserialize_dict(data, klass.__args__[1])
|
||||
else:
|
||||
return deserialize_model(data, klass)
|
||||
|
||||
|
||||
def _deserialize_primitive(data, klass):
|
||||
"""
|
||||
Deserializes to primitive type.
|
||||
|
||||
:param data: data to deserialize.
|
||||
:param klass: class literal.
|
||||
|
||||
:return: int, long, float, str, bool.
|
||||
:rtype: int | long | float | str | bool
|
||||
"""
|
||||
try:
|
||||
value = klass(data)
|
||||
except UnicodeEncodeError:
|
||||
value = unicode(data)
|
||||
except TypeError:
|
||||
value = data
|
||||
return value
|
||||
|
||||
|
||||
def _deserialize_object(value):
|
||||
"""
|
||||
Return a original value.
|
||||
|
||||
:return: object.
|
||||
"""
|
||||
return value
|
||||
|
||||
|
||||
def deserialize_date(string):
|
||||
"""
|
||||
Deserializes string to date.
|
||||
|
||||
:param string: str.
|
||||
:type string: str
|
||||
:return: date.
|
||||
:rtype: date
|
||||
"""
|
||||
try:
|
||||
from dateutil.parser import parse
|
||||
return parse(string).date()
|
||||
except ImportError:
|
||||
return string
|
||||
|
||||
|
||||
def deserialize_datetime(string):
|
||||
"""
|
||||
Deserializes string to datetime.
|
||||
|
||||
The string should be in iso8601 datetime format.
|
||||
|
||||
:param string: str.
|
||||
:type string: str
|
||||
:return: datetime.
|
||||
:rtype: datetime
|
||||
"""
|
||||
try:
|
||||
from dateutil.parser import parse
|
||||
return parse(string)
|
||||
except ImportError:
|
||||
return string
|
||||
|
||||
|
||||
def deserialize_model(data, klass):
|
||||
"""
|
||||
Deserializes list or dict to model.
|
||||
|
||||
:param data: dict, list.
|
||||
:type data: dict | list
|
||||
:param klass: class literal.
|
||||
:return: model object.
|
||||
"""
|
||||
instance = klass()
|
||||
|
||||
if not instance.swagger_types:
|
||||
return data
|
||||
|
||||
for attr, attr_type in iteritems(instance.swagger_types):
|
||||
if data is not None \
|
||||
and instance.attribute_map[attr] in data \
|
||||
and isinstance(data, (list, dict)):
|
||||
value = data[instance.attribute_map[attr]]
|
||||
setattr(instance, attr, _deserialize(value, attr_type))
|
||||
|
||||
return instance
|
||||
|
||||
|
||||
def _deserialize_list(data, boxed_type):
|
||||
"""
|
||||
Deserializes a list and its elements.
|
||||
|
||||
:param data: list to deserialize.
|
||||
:type data: list
|
||||
:param boxed_type: class literal.
|
||||
|
||||
:return: deserialized list.
|
||||
:rtype: list
|
||||
"""
|
||||
return [_deserialize(sub_data, boxed_type)
|
||||
for sub_data in data]
|
||||
|
||||
|
||||
|
||||
def _deserialize_dict(data, boxed_type):
|
||||
"""
|
||||
Deserializes a dict and its elements.
|
||||
|
||||
:param data: dict to deserialize.
|
||||
:type data: dict
|
||||
:param boxed_type: class literal.
|
||||
|
||||
:return: deserialized dict.
|
||||
:rtype: dict
|
||||
"""
|
||||
return {k: _deserialize(v, boxed_type)
|
||||
for k, v in iteritems(data)}
|
||||
Reference in New Issue
Block a user