Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add endpoints for multiple schema definitions #80

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading