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

Use schemas to dynamically display UI #953

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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
50 changes: 49 additions & 1 deletion pydatalab/src/pydatalab/routes/v0_1/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from pydatalab import __version__
from pydatalab.blocks import BLOCK_TYPES
from pydatalab.config import CONFIG, FEATURE_FLAGS, FeatureFlags
from pydatalab.models import Person
from pydatalab.models import Collection, Person
from pydatalab.models.items import Item
from pydatalab.mongo import flask_mongo

from ._version import __api_version__
Expand Down Expand Up @@ -143,3 +144,50 @@ def list_block_types():
).json()
)
)


def get_all_items_models():
return Item.__subclasses__()


@INFO.route("/info/types", methods=["GET"])
def list_supported_types():
"""Returns a list of supported schemas."""
types = [cls.schema()["properties"]["type"]["default"] for cls in get_all_items_models()]
types.append(Collection.schema()["properties"]["type"]["default"])

return jsonify(types)


for model_class in get_all_items_models():
model_type = model_class.schema()["properties"]["type"]["default"]

def make_route(model_class, model_type):
@INFO.route(
f"/info/types/{model_type}", methods=["GET"], endpoint=f"get_{model_type}_schema"
)
def get_model_schema():
"""Returns the JSON schema for the model."""
schema = model_class.schema()

response = {
"data": {
"schema": schema,
}
}
return jsonify(response)

make_route(model_class, model_type)


@INFO.route("/info/types/collections", methods=["GET"])
def get_collection_schema():
"""Returns the JSON schema for the Collection type."""
schema = Collection.schema()

response = {
"data": {
"schema": schema,
}
}
return jsonify(response)
Loading
Loading