[schema] fixes non-str keys in ORJSONResponse

This commit is contained in:
Maxime Alves LIRMM 2020-09-29 15:29:54 +02:00
parent 7d6bc2c181
commit 360f59b6ba
2 changed files with 26 additions and 24 deletions

View File

@ -47,7 +47,8 @@ class UnauthorizedResponse(Response):
class ORJSONResponse(JSONResponse):
def render(self, content: typ.Any) -> bytes:
return orjson.dumps(content)
return orjson.dumps(content,
option=orjson.OPT_NON_STR_KEYS)
class HJSONResponse(ORJSONResponse):

View File

@ -5,10 +5,31 @@ from .routes import gen_starlette_routes, api_routes
from .responses import *
from starlette.schemas import SchemaGenerator
from starlette.routing import Router
schemas = SchemaGenerator(
SCHEMAS = SchemaGenerator(
{"openapi": "3.0.0", "info": {"title": "HalfAPI", "version": "1.0"}}
)
"""
example: > {
"dummy_domain": {
"/abc/alphabet/organigramme": {
"fqtn": null,
"params": [
{}
],
"verb": "GET"
},
"/act/personne/": {
"fqtn": "acteur.personne",
"params": [
{}
"verb": "GET"
}
}
}
"""
async def get_api_routes(request, *args, **kwargs):
"""
@ -16,26 +37,6 @@ async def get_api_routes(request, *args, **kwargs):
200:
description: Returns the current API routes description (HalfAPI 0.2.1)
as a JSON object
example:
{
"dummy_domain": {
"/abc/alphabet/organigramme": {
"fqtn": null,
"params": [
{}
],
"verb": "GET"
},
"/act/personne/": {
"fqtn": "acteur.personne",
"params": [
{}
"verb": "GET"
}
}
}
"""
#TODO: LADOC
d_api = {}
@ -52,7 +53,7 @@ async def schema_json(request, *args, **kwargs):
as a JSON object
"""
return ORJSONResponse(
schemas.get_schema(routes=request.app.routes))
SCHEMAS.get_schema(routes=request.app.routes))
def schema_dict_dom(m_domain: ModuleType) -> Dict:
@ -71,4 +72,4 @@ def schema_dict_dom(m_domain: ModuleType) -> Dict:
"""
routes = [
elt for elt in gen_starlette_routes(m_domain) ]
return schemas.get_schema(routes=routes)
return SCHEMAS.get_schema(routes=routes)