diff --git a/halfapi/lib/constants.py b/halfapi/lib/constants.py index 562c174..294fec9 100644 --- a/halfapi/lib/constants.py +++ b/halfapi/lib/constants.py @@ -1 +1,27 @@ +from schema import Schema, Optional + VERBS = ('GET', 'POST', 'PUT', 'PATCH', 'DELETE') + +ACLS_SCHEMA = Schema([{ + 'acl': str, + Optional('args'): { + Optional('required'): { str }, + Optional('optional'): { str } + }, + Optional('out'): { str } +}]) + +ROUTE_SCHEMA = Schema({ + str: { + 'docs': lambda n: True, # Should validate an openAPI spec + 'acls': ACLS_SCHEMA + } +}) + +DOMAIN_SCHEMA = Schema({ + str: ROUTE_SCHEMA +}) + +API_SCHEMA = Schema({ + str: DOMAIN_SCHEMA # key: domain name, value: result of lib.routes.api_routes(domain_module) +}) diff --git a/tests/test_constants.py b/tests/test_constants.py new file mode 100644 index 0000000..c9cd49c --- /dev/null +++ b/tests/test_constants.py @@ -0,0 +1,14 @@ +from schema import Schema +def test_constants(): + from halfapi.lib.constants import ( + VERBS, + ACLS_SCHEMA, + ROUTE_SCHEMA, + DOMAIN_SCHEMA, + API_SCHEMA) + + assert isinstance(VERBS, tuple) + assert isinstance(ACLS_SCHEMA, Schema) + assert isinstance(ROUTE_SCHEMA, Schema) + assert isinstance(DOMAIN_SCHEMA, Schema) + assert isinstance(API_SCHEMA, Schema)