diff --git a/emannotationschemas/blueprint_app.py b/emannotationschemas/blueprint_app.py index df1df1d..f0880a1 100644 --- a/emannotationschemas/blueprint_app.py +++ b/emannotationschemas/blueprint_app.py @@ -1,5 +1,5 @@ from flask import abort -from flask_restx import Namespace, Resource +from flask_restx import Namespace, Resource, reqparse from marshmallow_jsonschema import JSONSchema from emannotationschemas import get_schema, get_types @@ -39,3 +39,23 @@ class SchemaAnnotationType(Resource): @api_bp.doc("get_annotation_type", security="apikey") def get(self, annotation_type: str): return get_type_schema(annotation_type) + + +schema_parser = reqparse.RequestParser() +schema_parser.add_argument( + "schema_names", type=str, action="split", help="list of annotation ids" +) +@api_bp.expect(schema_parser) +@api_bp.route("/types") +class SchemaAnnotationTypes(Resource): + @api_bp.doc("get_mutiple_types", security="apikey") + def post(self): + args = schema_parser.parse_args() + return {sn: get_type_schema(sn) for sn in args.get("schema_names", [])} + +@api_bp.route("/types_all") +class SchemaAnnotationTypes(Resource): + @api_bp.doc("get_all_types", security="apikey") + def get(self): + schema_names = get_types() + return {sn: get_type_schema(sn) for sn in schema_names} diff --git a/requirements.txt b/requirements.txt index 30da994..f277d89 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,3 @@ jsonschema<4.0 SQLAlchemy<1.4 shapely==2.0.3 geoalchemy2>=0.11.1, <0.12.0 - diff --git a/tests/test_schema_blueprint.py b/tests/test_schema_blueprint.py index abd7d17..692d8de 100644 --- a/tests/test_schema_blueprint.py +++ b/tests/test_schema_blueprint.py @@ -24,3 +24,8 @@ def test_get_synapse_schema(app, client): assert "SynapseSchema" in schema["definitions"] assert "pre_pt" in schema["definitions"]["SynapseSchema"]["properties"] assert "post_pt" in schema["definitions"]["SynapseSchema"]["properties"] + +def test_all_types(client): + response = client.get("/schema/api/v2/types_all") + assert response.status_code == 200 + assert isinstance(response.json, dict)