From d7fe95b37eaeefe0eb88b7df55b427ee09d08cad Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Mon, 2 Oct 2023 15:16:28 +0200 Subject: [PATCH] Add OPTIMADE properties to the info endpoint --- src/mc_optimade/mc_optimade/convert.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/mc_optimade/mc_optimade/convert.py b/src/mc_optimade/mc_optimade/convert.py index 0367b75..0e8e950 100644 --- a/src/mc_optimade/mc_optimade/convert.py +++ b/src/mc_optimade/mc_optimade/convert.py @@ -11,6 +11,7 @@ import tqdm from optimade.models import EntryInfoResource, EntryResource +from optimade.server.schemas import ENTRY_INFO_SCHEMAS, retrieve_queryable_properties from .config import Config, EntryConfig, ParsedFiles, PropertyDefinition from .parsers import ENTRY_PARSERS, OPTIMADE_CONVERTERS, PROPERTY_PARSERS, TYPE_MAP @@ -23,12 +24,17 @@ def _construct_entry_type_info( ) -> EntryInfoResource: """Take the provided property definitions and construct an entry info response. - TODO: Also insert the relevant default OPTIMADE fields. - Returns: The full `EntryInfoResource` object. """ + + default_properties = {} + if type in ENTRY_INFO_SCHEMAS: + default_properties = retrieve_queryable_properties( + ENTRY_INFO_SCHEMAS[type](), {"id", "type", "attributes"} + ) + info: dict[str, Any] = {"formats": ["json"], "description": type} info["properties"] = { f"_{provider_prefix}_{p.name}": { @@ -39,6 +45,7 @@ def _construct_entry_type_info( } for p in properties } + info["properties"].update(default_properties) info["output_fields_by_format"] = {} info["output_fields_by_format"]["json"] = list(info["properties"].keys()) return EntryInfoResource(**info)