Skip to content

Commit

Permalink
Merge pull request #80 from seung-lab/get_many_schema
Browse files Browse the repository at this point in the history
add endpoints for multiple schema definitions
  • Loading branch information
fcollman authored Mar 6, 2024
2 parents c930a2a + dbdef39 commit b7ccaea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
22 changes: 21 additions & 1 deletion emannotationschemas/blueprint_app.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ jsonschema<4.0
SQLAlchemy<1.4
shapely==2.0.3
geoalchemy2>=0.11.1, <0.12.0

5 changes: 5 additions & 0 deletions tests/test_schema_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit b7ccaea

Please sign in to comment.