Python AIOHTTP server generator (#1470)

* Astract factory for generators based on connexion

* Add aiohttp server generator

* Fix flask tests

* Normalize python-flask folder names
This commit is contained in:
Jyhess
2019-01-11 16:35:21 +01:00
committed by William Cheng
parent 4652023b7c
commit 80ca67cfda
160 changed files with 5404 additions and 815 deletions

View File

@@ -0,0 +1,9 @@
# coding: utf-8
# import models into model package
from openapi_server.models.api_response import ApiResponse
from openapi_server.models.category import Category
from openapi_server.models.order import Order
from openapi_server.models.pet import Pet
from openapi_server.models.tag import Tag
from openapi_server.models.user import User

View File

@@ -0,0 +1,110 @@
# coding: utf-8
from datetime import date, datetime
from typing import List, Dict, Type
from openapi_server.models.base_model_ import Model
from openapi_server import util
class ApiResponse(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""
def __init__(self, code: int=None, type: str=None, message: str=None):
"""ApiResponse - a model defined in OpenAPI
:param code: The code of this ApiResponse.
:param type: The type of this ApiResponse.
:param message: The message of this ApiResponse.
"""
self.openapi_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: dict) -> 'ApiResponse':
"""Returns the dict as a model
:param dikt: A dict.
:return: The ApiResponse of this ApiResponse.
"""
return util.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

View File

@@ -0,0 +1,66 @@
import pprint
import typing
from openapi_server import util
T = typing.TypeVar('T')
class Model(object):
# openapiTypes: The key is attribute name and the
# value is attribute type.
openapi_types = {}
# attributeMap: The key is attribute name and the
# value is json key in definition.
attribute_map = {}
@classmethod
def from_dict(cls: T, dikt: dict) -> T:
"""Returns the dict as a model"""
return util.deserialize_model(dikt, cls)
def to_dict(self) -> dict:
"""Returns the model properties as a dict
"""
result = {}
for attr_key, json_key in self.attribute_map.items():
value = getattr(self, attr_key)
if value is None:
continue
if isinstance(value, list):
result[json_key] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[json_key] = value.to_dict()
elif isinstance(value, dict):
result[json_key] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
else:
result[json_key] = value
return result
def to_str(self) -> str:
"""Returns the string representation of the model
"""
return pprint.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

View File

@@ -0,0 +1,85 @@
# coding: utf-8
from datetime import date, datetime
from typing import List, Dict, Type
from openapi_server.models.base_model_ import Model
from openapi_server import util
class Category(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""
def __init__(self, id: int=None, name: str=None):
"""Category - a model defined in OpenAPI
:param id: The id of this Category.
:param name: The name of this Category.
"""
self.openapi_types = {
'id': int,
'name': str
}
self.attribute_map = {
'id': 'id',
'name': 'name'
}
self._id = id
self._name = name
@classmethod
def from_dict(cls, dikt: dict) -> 'Category':
"""Returns the dict as a model
:param dikt: A dict.
:return: The Category of this Category.
"""
return util.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

View File

@@ -0,0 +1,193 @@
# coding: utf-8
from datetime import date, datetime
from typing import List, Dict, Type
from openapi_server.models.base_model_ import Model
from openapi_server import util
class Order(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""
def __init__(self, id: int=None, pet_id: int=None, quantity: int=None, ship_date: datetime=None, status: str=None, complete: bool=False):
"""Order - a model defined in OpenAPI
:param id: The id of this Order.
:param pet_id: The pet_id of this Order.
:param quantity: The quantity of this Order.
:param ship_date: The ship_date of this Order.
:param status: The status of this Order.
:param complete: The complete of this Order.
"""
self.openapi_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: dict) -> 'Order':
"""Returns the dict as a model
:param dikt: A dict.
:return: The Order of this Order.
"""
return util.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

View File

@@ -0,0 +1,199 @@
# coding: utf-8
from datetime import date, datetime
from typing import List, Dict, Type
from openapi_server.models.base_model_ import Model
from openapi_server.models.category import Category
from openapi_server.models.tag import Tag
from openapi_server import util
class Pet(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""
def __init__(self, id: int=None, category: Category=None, name: str=None, photo_urls: List[str]=None, tags: List[Tag]=None, status: str=None):
"""Pet - a model defined in OpenAPI
:param id: The id of this Pet.
:param category: The category of this Pet.
:param name: The name of this Pet.
:param photo_urls: The photo_urls of this Pet.
:param tags: The tags of this Pet.
:param status: The status of this Pet.
"""
self.openapi_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: dict) -> 'Pet':
"""Returns the dict as a model
:param dikt: A dict.
:return: The Pet of this Pet.
"""
return util.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

View File

@@ -0,0 +1,85 @@
# coding: utf-8
from datetime import date, datetime
from typing import List, Dict, Type
from openapi_server.models.base_model_ import Model
from openapi_server import util
class Tag(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""
def __init__(self, id: int=None, name: str=None):
"""Tag - a model defined in OpenAPI
:param id: The id of this Tag.
:param name: The name of this Tag.
"""
self.openapi_types = {
'id': int,
'name': str
}
self.attribute_map = {
'id': 'id',
'name': 'name'
}
self._id = id
self._name = name
@classmethod
def from_dict(cls, dikt: dict) -> 'Tag':
"""Returns the dict as a model
:param dikt: A dict.
:return: The Tag of this Tag.
"""
return util.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

View File

@@ -0,0 +1,237 @@
# coding: utf-8
from datetime import date, datetime
from typing import List, Dict, Type
from openapi_server.models.base_model_ import Model
from openapi_server import util
class User(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""
def __init__(self, id: int=None, username: str=None, first_name: str=None, last_name: str=None, email: str=None, password: str=None, phone: str=None, user_status: int=None):
"""User - a model defined in OpenAPI
:param id: The id of this User.
:param username: The username of this User.
:param first_name: The first_name of this User.
:param last_name: The last_name of this User.
:param email: The email of this User.
:param password: The password of this User.
:param phone: The phone of this User.
:param user_status: The user_status of this User.
"""
self.openapi_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: dict) -> 'User':
"""Returns the dict as a model
:param dikt: A dict.
:return: The User of this User.
"""
return util.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