Add collection info to /server-result #176

Merged
christian-monch merged 4 commits from issue-175 into master 2025-12-02 20:52:11 +00:00
5 changed files with 85 additions and 3 deletions

View file

@ -1,3 +1,11 @@
# 5.3.0 (2025-12-02)
## New features
- The `/server`-endpoint result now contains the name of collections and the
schemas that are used by the collections.
# 5.2.1 (2025-11-26) # 5.2.1 (2025-11-26)
## Changes ## Changes

View file

@ -701,7 +701,17 @@ The service provides the following user endpoints (in addition to user-endpoints
The response is a JSON object with the following structure: The response is a JSON object with the following structure:
```json ```json
{ {
"version": "<version of the server>" "version": "<version of the server>",
"collections": [
{
"name": "collection_1",
"schema": "https://example.org/schema_1.yaml"
},
{
"name": "collection_2",
"schema": "https://example.org/schema_2.yaml"
},
]
} }
``` ```

View file

@ -1 +1 @@
__version__ = '5.2.1' __version__ = '5.3.0'

View file

@ -97,8 +97,18 @@ class TokenCapabilityRequest(BaseModel):
token: str | None token: str | None
class ServerCollectionResponse(BaseModel):
name: str
schema: str
class ServerCollectionCountedResponse(ServerCollectionResponse):
records: int
class ServerResponse(BaseModel): class ServerResponse(BaseModel):
version: str version: str
collections: list[ServerCollectionResponse|ServerCollectionCountedResponse]
logging.basicConfig(level=logging.WARNING) logging.basicConfig(level=logging.WARNING)
@ -393,9 +403,16 @@ def validate_record(
tags=['Server info'], tags=['Server info'],
name='get server information' name='get server information'
) )
async def get_server() -> ServerResponse: async def server() -> ServerResponse:
return ServerResponse( return ServerResponse(
version = __version__, version = __version__,
collections = [
ServerCollectionResponse(
name=collection_name,
schema=g_instance_config.schemas[collection_name],
)
for collection_name in g_instance_config.collections
]
) )

View file

@ -1,3 +1,5 @@
from pathlib import Path
import pytest # F401 import pytest # F401
from .. import ( from .. import (
@ -14,6 +16,9 @@ from .create_store import (
) )
from .test_utils import basic_write_locations from .test_utils import basic_write_locations
# Path to a local simple test schema
schema_file = Path(__file__).parent / 'testschema.yaml'
extra_record = { extra_record = {
'schema_type': 'abc:Person', 'schema_type': 'abc:Person',
'pid': 'abc:aaaa', 'pid': 'abc:aaaa',
@ -390,6 +395,48 @@ def test_server(fastapi_client_simple):
assert response.status_code == HTTP_200_OK assert response.status_code == HTTP_200_OK
assert response.json() == { assert response.json() == {
'version': __version__, 'version': __version__,
'collections': [
{
'name': 'collection_1',
'schema': str(schema_file),
},
{
'name': 'collection_2',
'schema': str(schema_file),
},
{
'name': 'collection_3',
'schema': str(schema_file),
},
{
'name': 'collection_4',
'schema': str(schema_file),
},
{
'name': 'collection_5',
'schema': str(schema_file),
},
{
'name': 'collection_6',
'schema': str(schema_file),
},
{
'name': 'collection_7',
'schema': str(schema_file),
},
{
'name': 'collection_8',
'schema': str(schema_file),
},
{
'name': 'collection_dlflatsocial-1',
'schema': 'https://concepts.datalad.org/s/flat-social/unreleased.yaml',
},
{
'name': 'collection_dlflatsocial-2',
'schema': 'https://concepts.datalad.org/s/flat-social/unreleased.yaml',
},
],
} }