[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): class ORJSONResponse(JSONResponse):
def render(self, content: typ.Any) -> bytes: def render(self, content: typ.Any) -> bytes:
return orjson.dumps(content) return orjson.dumps(content,
option=orjson.OPT_NON_STR_KEYS)
class HJSONResponse(ORJSONResponse): class HJSONResponse(ORJSONResponse):

View File

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