[cli.routes] add json schema export
This commit is contained in:
parent
429a90d786
commit
238bd99bd3
@ -6,6 +6,7 @@ cli/routes.py Defines the "halfapi routes" cli commands
|
||||
import sys
|
||||
import importlib
|
||||
from pprint import pprint
|
||||
import orjson
|
||||
|
||||
import click
|
||||
|
||||
@ -14,7 +15,8 @@ from .cli import cli
|
||||
from ..logging import logger
|
||||
|
||||
from ..lib.domain import domain_schema_dict
|
||||
from ..lib.constants import DOMAIN_SCHEMA
|
||||
from ..lib.constants import DOMAIN_SCHEMA, ROUTE_SCHEMA
|
||||
from ..lib.responses import ORJSONResponse
|
||||
# from ..lib.routes import api_routes
|
||||
from ..lib.schemas import schema_to_csv # get_api_routes
|
||||
|
||||
@ -37,15 +39,18 @@ def routes(module, export=False, validate=False, check=False, noheader=False, sc
|
||||
if export:
|
||||
click.echo(schema_to_csv(module, header=not noheader))
|
||||
|
||||
if schema:
|
||||
routes_d = domain_schema_dict(mod)
|
||||
ROUTE_SCHEMA.validate(routes_d)
|
||||
click.echo(orjson.dumps(routes_d,
|
||||
option=orjson.OPT_NON_STR_KEYS,
|
||||
default=ORJSONResponse.default_cast))
|
||||
|
||||
|
||||
if validate:
|
||||
routes_d = domain_schema_dict(mod)
|
||||
try:
|
||||
DOMAIN_SCHEMA.validate(routes_d[0])
|
||||
ROUTE_SCHEMA.validate(routes_d)
|
||||
except Exception as exc:
|
||||
pprint(routes_d[0])
|
||||
raise exc from exc
|
||||
raise exc
|
||||
|
||||
"""
|
||||
if schema:
|
||||
click.echo(get_api_routes(uu
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user