feat(CRUK): add 1.0.0 and GWDM 2.1 mapping#130
Conversation
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.
|
|
||
| from hdr_schemata.models.GWDM.v2_0.Summary import Summary as Gwdm20Summary | ||
|
|
||
| LineSeparatedValues = constr(pattern=r"([^\r\n]+)") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
LineSepartedValues is a definition?
| 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 |
There was a problem hiding this comment.
again - where/why is this used? translation maps in JSONata handle the translations between schemas not python code
- 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.
|
All change requests actioned, and signed off. Merging. |
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.