forked from loafle/openapi-generator-original
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:
@@ -0,0 +1,114 @@
|
||||
from typing import List, Dict
|
||||
from aiohttp import web
|
||||
|
||||
from openapi_server.models.api_response import ApiResponse
|
||||
from openapi_server.models.pet import Pet
|
||||
from openapi_server import util
|
||||
|
||||
|
||||
async def add_pet(request: web.Request, body) -> web.Response:
|
||||
"""Add a new pet to the store
|
||||
|
||||
|
||||
|
||||
:param body: Pet object that needs to be added to the store
|
||||
:type body: dict | bytes
|
||||
|
||||
"""
|
||||
body = Pet.from_dict(body)
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
async def delete_pet(request: web.Request, pet_id, api_key=None) -> web.Response:
|
||||
"""Deletes a pet
|
||||
|
||||
|
||||
|
||||
:param pet_id: Pet id to delete
|
||||
:type pet_id: int
|
||||
:param api_key:
|
||||
:type api_key: str
|
||||
|
||||
"""
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
async def find_pets_by_status(request: web.Request, status) -> web.Response:
|
||||
"""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]
|
||||
|
||||
"""
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
async def find_pets_by_tags(request: web.Request, tags) -> web.Response:
|
||||
"""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]
|
||||
|
||||
"""
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
async def get_pet_by_id(request: web.Request, pet_id) -> web.Response:
|
||||
"""Find pet by ID
|
||||
|
||||
Returns a single pet
|
||||
|
||||
:param pet_id: ID of pet to return
|
||||
:type pet_id: int
|
||||
|
||||
"""
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
async def update_pet(request: web.Request, body) -> web.Response:
|
||||
"""Update an existing pet
|
||||
|
||||
|
||||
|
||||
:param body: Pet object that needs to be added to the store
|
||||
:type body: dict | bytes
|
||||
|
||||
"""
|
||||
body = Pet.from_dict(body)
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
async def update_pet_with_form(request: web.Request, pet_id, name=None, status=None) -> web.Response:
|
||||
"""Updates a pet in the store with form data
|
||||
|
||||
|
||||
|
||||
:param pet_id: ID of pet that needs to be updated
|
||||
:type pet_id: int
|
||||
:param name: Updated name of the pet
|
||||
:type name: str
|
||||
:param status: Updated status of the pet
|
||||
:type status: str
|
||||
|
||||
"""
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
async def upload_file(request: web.Request, pet_id, additional_metadata=None, file=None) -> web.Response:
|
||||
"""uploads an image
|
||||
|
||||
|
||||
|
||||
:param pet_id: ID of pet to update
|
||||
:type pet_id: int
|
||||
:param additional_metadata: Additional data to pass to server
|
||||
:type additional_metadata: str
|
||||
:param file: file to upload
|
||||
:type file: str
|
||||
|
||||
"""
|
||||
return web.Response(status=200)
|
||||
@@ -0,0 +1,29 @@
|
||||
from typing import List
|
||||
|
||||
|
||||
def info_from_api_key(api_key: str, required_scopes: None) -> dict:
|
||||
"""
|
||||
Check and retrieve authentication information from api_key.
|
||||
Returned value will be passed in 'token_info' parameter of your operation function, if there is one.
|
||||
'sub' or 'uid' will be set in 'user' parameter of your operation function, if there is one.
|
||||
Should return None if api_key is invalid or does not allow access to called API.
|
||||
"""
|
||||
return {'uid': 'user_id'}
|
||||
|
||||
|
||||
def info_from_petstore_auth(token: str) -> dict:
|
||||
"""
|
||||
Validate and decode token.
|
||||
Returned value will be passed in 'token_info' parameter of your operation function, if there is one.
|
||||
'sub' or 'uid' will be set in 'user' parameter of your operation function, if there is one.
|
||||
'scope' or 'scopes' will be passed to scope validation function.
|
||||
Should return None if token is invalid or does not allow access to called API.
|
||||
"""
|
||||
return {'scopes': ['read:pets', 'write:pets'], 'uid': 'user_id'}
|
||||
|
||||
|
||||
def validate_scope_petstore_auth(required_scopes: List[str], token_scopes: List[str]) -> bool:
|
||||
""" Validate required scopes are included in token scope """
|
||||
return set(required_scopes).issubset(set(token_scopes))
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
from typing import List, Dict
|
||||
from aiohttp import web
|
||||
|
||||
from openapi_server.models.order import Order
|
||||
from openapi_server import util
|
||||
|
||||
|
||||
async def delete_order(request: web.Request, order_id) -> web.Response:
|
||||
"""Delete purchase order by ID
|
||||
|
||||
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
|
||||
:param order_id: ID of the order that needs to be deleted
|
||||
:type order_id: str
|
||||
|
||||
"""
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
async def get_inventory(request: web.Request, ) -> web.Response:
|
||||
"""Returns pet inventories by status
|
||||
|
||||
Returns a map of status codes to quantities
|
||||
|
||||
|
||||
"""
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
async def get_order_by_id(request: web.Request, order_id) -> web.Response:
|
||||
"""Find purchase order by ID
|
||||
|
||||
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
|
||||
:param order_id: ID of pet that needs to be fetched
|
||||
:type order_id: int
|
||||
|
||||
"""
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
async def place_order(request: web.Request, body) -> web.Response:
|
||||
"""Place an order for a pet
|
||||
|
||||
|
||||
|
||||
:param body: order placed for purchasing the pet
|
||||
:type body: dict | bytes
|
||||
|
||||
"""
|
||||
body = Order.from_dict(body)
|
||||
return web.Response(status=200)
|
||||
@@ -0,0 +1,107 @@
|
||||
from typing import List, Dict
|
||||
from aiohttp import web
|
||||
|
||||
from openapi_server.models.user import User
|
||||
from openapi_server import util
|
||||
|
||||
|
||||
async def create_user(request: web.Request, body) -> web.Response:
|
||||
"""Create user
|
||||
|
||||
This can only be done by the logged in user.
|
||||
|
||||
:param body: Created user object
|
||||
:type body: dict | bytes
|
||||
|
||||
"""
|
||||
body = User.from_dict(body)
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
async def create_users_with_array_input(request: web.Request, body) -> web.Response:
|
||||
"""Creates list of users with given input array
|
||||
|
||||
|
||||
|
||||
:param body: List of user object
|
||||
:type body: list | bytes
|
||||
|
||||
"""
|
||||
body = [User.from_dict(d) for d in body]
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
async def create_users_with_list_input(request: web.Request, body) -> web.Response:
|
||||
"""Creates list of users with given input array
|
||||
|
||||
|
||||
|
||||
:param body: List of user object
|
||||
:type body: list | bytes
|
||||
|
||||
"""
|
||||
body = [User.from_dict(d) for d in body]
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
async def delete_user(request: web.Request, username) -> web.Response:
|
||||
"""Delete user
|
||||
|
||||
This can only be done by the logged in user.
|
||||
|
||||
:param username: The name that needs to be deleted
|
||||
:type username: str
|
||||
|
||||
"""
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
async def get_user_by_name(request: web.Request, username) -> web.Response:
|
||||
"""Get user by user name
|
||||
|
||||
|
||||
|
||||
:param username: The name that needs to be fetched. Use user1 for testing.
|
||||
:type username: str
|
||||
|
||||
"""
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
async def login_user(request: web.Request, username, password) -> web.Response:
|
||||
"""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
|
||||
|
||||
"""
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
async def logout_user(request: web.Request, ) -> web.Response:
|
||||
"""Logs out current logged in user session
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
return web.Response(status=200)
|
||||
|
||||
|
||||
async def update_user(request: web.Request, username, body) -> web.Response:
|
||||
"""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
|
||||
|
||||
"""
|
||||
body = User.from_dict(body)
|
||||
return web.Response(status=200)
|
||||
Reference in New Issue
Block a user