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

Multischema endpoint #158

Merged
merged 8 commits into from
Mar 13, 2024
Merged
Changes from 1 commit
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
Next Next commit
add multi-schema endpoints
ceesem committed Mar 9, 2024
commit 1fda8a96f1883b6b98e445aebe2887841c5bcf1a
38 changes: 35 additions & 3 deletions caveclient/emannotationschemas.py
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ def __init__(
over_client=over_client,
)

def get_schemas(self):
def get_schemas(self) -> list[str]:
"""Get the available schema types

Returns
@@ -77,8 +77,8 @@ def get_schemas(self):
url = self._endpoints["schema"].format_map(endpoint_mapping)
response = self.session.get(url)
return handle_response(response)

def schema_definition(self, schema_type):
def schema_definition(self, schema_type: str) -> dict[str]:
"""Get the definition of a specified schema_type

Parameters
@@ -97,6 +97,38 @@ def schema_definition(self, schema_type):
response = self.session.get(url)
return handle_response(response)

def schema_definition_multi(self, schema_types: list[str]) -> dict:
"""Get the definition of multiple schema_types

Parameters
----------
schema_types : list
List of schema names

Returns
-------
dict
Dictionary of schema definitions, keys are schema names values are definitions.
"""
endpoint_mapping = self.default_url_mapping
url = self._endpoints["schema_definition_multi"].format_map(endpoint_mapping)
data={'schema_names': schema_types}
response = self.session.post(url, params=data)
return handle_response(response)

def schema_definition_all(self) -> dict[str]:
"""Get the definition of all schema_types

Returns
-------
dict
Dictionary of schema definitions, keys are schema names values are definitions.
"""
endpoint_mapping = self.default_url_mapping
url = self._endpoints["schema_definition_all"].format_map(endpoint_mapping)
response = self.session.get(url)
return handle_response(response)


client_mapping = {
1: SchemaClientLegacy,
2 changes: 2 additions & 0 deletions caveclient/endpoints.py
Original file line number Diff line number Diff line change
@@ -200,6 +200,8 @@
schema_endpoints_v2 = {
"schema": schema_v2 + "/type",
"schema_definition": schema_v2 + "/type/{schema_type}",
"schema_definition_multi": schema_v2 + "/types",
"schema_definition_all": schema_v2 + "/types_all",
}

schema_api_versions = {1: schema_endpoints_v1, 2: schema_endpoints_v2}