Skip to content

feat(CRUK): add 1.0.0 and GWDM 2.1 mapping#130

Merged
loki-sinclair-hdruk merged 3 commits into
devfrom
feature/cruk-schemata-clean
May 27, 2026
Merged

feat(CRUK): add 1.0.0 and GWDM 2.1 mapping#130
loki-sinclair-hdruk merged 3 commits into
devfrom
feature/cruk-schemata-clean

Conversation

@cocoon02

Copy link
Copy Markdown
Collaborator

Add CRUK 1.0.0 model/schema/example and register in available.json.\nAdd GWDM 2.1 model/schema with helpers to map into CRUK.

Add CRUK 1.0.0 model/schema/example and register in available.json.\nAdd GWDM 2.1 model/schema with helpers to map into CRUK.
Adds DataTable.size and Summary leadResearcher/leadResearchInstitute to CRUK 1.0.0 and updates the CRUK Pydantic model wiring so the generated schema matches the checked-in schema.
Comment thread hdr_schemata/models/CRUK/v1_0_0/__init__.py Outdated
Comment thread hdr_schemata/models/GWDM/2.1/schema.json Outdated
Comment thread hdr_schemata/models/CRUK/1.0.0/schema.json Outdated

from hdr_schemata.models.GWDM.v2_0.Summary import Summary as Gwdm20Summary

LineSeparatedValues = constr(pattern=r"([^\r\n]+)")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why line separated? why not use the common comma separated?

Also this definition, if it's really needed, if it is to be reused/shared, should be in the definitions and imported from there

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used newline separation so funder names can contain commas and to match a one-funder-per-line UI;But I have updated with the CommaSeparatedValues.

with open(location, "w") as f:
json.dump(cls.model_json_schema(), f, indent=6)

def to_hdruk400_payload(self) -> Dict[str, Any]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where's this used? we use the translation maps to translate between the two - not the python code. These schemas are published in python and JSON, so this wouldnt work in JSON.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right . I have updated it.

from hdr_schemata.models.HDRUK.v4_0_0 import Hdruk400
from hdr_schemata.definitions.HDRUK import Description, OneHundredFiftyCharacters

from .Summary import LineSeparatedValues, Summary

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LineSepartedValues is a definition?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines +162 to +188
def to_cruk100_payload(self) -> Dict[str, Any]:
payload = self.to_hdruk400_payload()

# CRUK 1.0.0 extends HDRUK 4.0.0 with additional fields.
# GWDM 2.1 already has these fields, so pass them through.
if self.icons is not None:
payload["icons"] = self.icons
if self.datasetFilters is not None:
payload["datasetFilters"] = [
df.model_dump(mode="json") if hasattr(df, "model_dump") else df
for df in self.datasetFilters
if df is not None
] or None
if self.projectGrants is not None:
payload["projectGrants"] = [
pg.model_dump(mode="json") if hasattr(pg, "model_dump") else pg
for pg in self.projectGrants
if pg is not None
] or None
if self.erd is not None:
# CRUK expects a URL; GWDM carries an Image object. Prefer the image string if present.
image_value = getattr(self.erd, "image", None)
if image_value is not None and hasattr(image_value, "root"):
image_value = image_value.root
payload["erd"] = image_value

return payload

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again - where/why is this used? translation maps in JSONata handle the translations between schemas not python code

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment thread hdr_schemata/models/CRUK/v1_0_0/__init__.py
- Close parenthesis in projectGrantName description (CRUK model and 1.0.0 schema).
- GWDM 2.1: use CommaSeparatedValues for funders; sync 2.1 schema.json.
- Remove unused Gwdm21 Python helpers (to_hdruk400 / to_cruk100); translation maps remain canonical.
- test_gwdm: build Gwdm10 JSON Schema in a subprocess so $defs matches committed schema when CRUK loads first.
@loki-sinclair-hdruk

Copy link
Copy Markdown
Contributor

All change requests actioned, and signed off. Merging.

@loki-sinclair-hdruk loki-sinclair-hdruk merged commit 6c17921 into dev May 27, 2026
3 checks passed
@loki-sinclair-hdruk loki-sinclair-hdruk deleted the feature/cruk-schemata-clean branch May 27, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants