[schemas] supression des fonctions api_routes

This commit is contained in:
Maxime Alves LIRMM 2021-11-30 14:40:07 +01:00
parent 7230316296
commit ec26438340
4 changed files with 4 additions and 66 deletions

View File

@ -40,7 +40,7 @@ from halfapi.lib.responses import (ORJSONResponse, UnauthorizedResponse,
ServiceUnavailableResponse) ServiceUnavailableResponse)
from halfapi.lib.routes import gen_domain_routes, gen_schema_routes, JSONRoute from halfapi.lib.routes import gen_domain_routes, gen_schema_routes, JSONRoute
from halfapi.lib.schemas import get_api_routes, get_api_domain_routes, schema_json, get_acls from halfapi.lib.schemas import schema_json, get_acls
from halfapi.logging import logger, config_logging from halfapi.logging import logger, config_logging
from halfapi import __version__ from halfapi import __version__
@ -81,7 +81,7 @@ class HalfAPI:
DOMAINS[domain] = importlib.import_module(f'{domain}.{router}') DOMAINS[domain] = importlib.import_module(f'{domain}.{router}')
if DOMAINS: if DOMAINS:
self.api_routes = get_api_routes(DOMAINS) self.api_routes = {}
routes = [ Route('/', JSONRoute(self.api_routes)) ] routes = [ Route('/', JSONRoute(self.api_routes)) ]

View File

@ -1,7 +1,6 @@
""" Schemas module """ Schemas module
Functions : Functions :
- get_api_routes
- schema_json - schema_json
- schema_dict_dom - schema_dict_dom
- get_acls - get_acls
@ -27,67 +26,6 @@ SCHEMAS = SchemaGenerator(
{"openapi": "3.0.0", "info": {"title": "HalfAPI", "version": __version__}} {"openapi": "3.0.0", "info": {"title": "HalfAPI", "version": __version__}}
) )
def get_api_routes(domains: Dict[str, ModuleType]) -> Dict:
"""
description: Returns the current API routes dictionary
as a JSON object
example: {
"dummy_domain": {
"abc/alphabet": {
"GET": {
"docs": "",
"acls": [
{
"acl": "public"
}
]
}
},
"abc/alphabet/{test:uuid}": {
"GET": [
{
"acl": "public"
}
],
"POST": [
{
"acl": "public"
}
],
"PATCH": [
{
"acl": "public"
}
],
"PUT": [
{
"acl": "public"
}
]
}
}
}
"""
return {
domain: api_routes(m_domain)[0]
for domain, m_domain in domains.items()
}
def get_api_domain_routes(m_domain: ModuleType) -> Coroutine:
routes, _ = api_routes(m_domain)
async def wrapped(request, *args, **kwargs):
"""
description: Returns the current API routes dictionary for a specific
domain as a JSON object
"""
return ORJSONResponse(routes)
return wrapped
async def schema_json(request, *args, **kwargs): async def schema_json(request, *args, **kwargs):
""" """
description: Returns the current API routes description (OpenAPI v3) description: Returns the current API routes description (OpenAPI v3)

View File

@ -25,7 +25,7 @@ def test_error(application_debug):
r = c.get('/halfapi/error/500') r = c.get('/halfapi/error/500')
assert r.status_code == 500 assert r.status_code == 500
@pytest.skip @pytest.mark.skip
def test_exception(application_debug): def test_exception(application_debug):
c = TestClient(application_debug) c = TestClient(application_debug)
try: try:

View File

@ -16,7 +16,7 @@ def test_schemas_dict_dom():
'dummy_domain':routers}) 'dummy_domain':routers})
assert isinstance(schema, dict) assert isinstance(schema, dict)
def test_get_api_routes(project_runner, application_debug): def test_get_api_schema(project_runner, application_debug):
c = TestClient(application_debug) c = TestClient(application_debug)
r = c.get('/') r = c.get('/')
assert isinstance(c, TestClient) assert isinstance(c, TestClient)