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 all schemas view #78

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 3 additions & 3 deletions emannotationschemas/app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging

from flask import Blueprint, Flask, jsonify, redirect, url_for
from flask import Blueprint, Flask, jsonify, redirect
from flask_restx import Api

from flask_cors import CORS
from emannotationschemas.blueprint_app import api_bp
from emannotationschemas.config import configure_app
from emannotationschemas.utils import get_instance_folder_path
Expand All @@ -20,7 +20,7 @@ def create_app(test_config=None):
static_url_path="/schema/static",
instance_relative_config=True,
)

CORS(app, expose_headers="WWW-Authenticate")
logging.basicConfig(level=logging.DEBUG)

# load configuration (from test_config if passed)
Expand Down
29 changes: 28 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 All @@ -25,6 +25,14 @@ def get(self):
return get_types()


def get_type_schemas():
types = get_types()
type_schemas = {}
for type in types:
type_schemas[type] = get_type_schema(type)
return type_schemas


def get_type_schema(annotation_type):
try:
Schema = get_schema(annotation_type)
Expand All @@ -39,3 +47,22 @@ 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 schema names"
)


@api_bp.expect(schema_parser)
@api_bp.route("/type/schemas")
class SchemaAnnotationTypes(Resource):
@api_bp.doc("get_annotation_types", security="apikey")
def get(self):
args = schema_parser.parse_args()
schema_names = args.get("schema_names", None)
if schema_names is not None:
return {name: get_type_schema(name) for name in schema_names}
else:
return get_type_schemas()
Loading