From 314b30f4dc9843394f150844dbca518caa64f56b Mon Sep 17 00:00:00 2001 From: Branwen Snelling Date: Fri, 30 Aug 2024 10:04:24 +0100 Subject: [PATCH 1/2] update regex in hydration and revsions in GWDM --- docs/GWDM/2.0.form.json | 5 +++-- docs/GWDM/2.0.md | 6 +++--- docs/GWDM/2.0.structure.json | 5 +++-- docs/HDRUK/3.0.0.form.json | 3 ++- hdr_schemata/models/GWDM/2.0/schema.json | 5 ++++- hdr_schemata/models/GWDM/v2_0/Revision.py | 3 ++- hdr_schemata/utils/create_markdown.py | 1 + 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/docs/GWDM/2.0.form.json b/docs/GWDM/2.0.form.json index c5b82ce..82a72eb 100644 --- a/docs/GWDM/2.0.form.json +++ b/docs/GWDM/2.0.form.json @@ -66,7 +66,7 @@ "https://api.service.nhs.uk/health-research-data-catalogue/datasetrevisions/841f7da2-b018-41f6-b4ae-2e0aadab6561" ], "is_list": false, - "is_optional": false, + "is_optional": true, "types": { "title": "Url", "format": "uri", @@ -1593,5 +1593,6 @@ }, "location": "omics.platform" } - ] + ], + "url_regex": "(https?:\\/\\/)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[^\\s]*)?$" } \ No newline at end of file diff --git a/docs/GWDM/2.0.md b/docs/GWDM/2.0.md index 2b3d5f0..84df875 100644 --- a/docs/GWDM/2.0.md +++ b/docs/GWDM/2.0.md @@ -78,9 +78,9 @@ Examples: Some url with a reference to the record of a previous version of this dataset -| title | guidance | is_list | required | type | -|:-------------|:-----------|:----------|:-----------|:--------------------------------------------------------------------------------------------| -| revision url | | False | True | ["Url[{'anyOf': [{'format': 'uri', 'minLength': 1, 'type': 'string'}, {'type': 'null'}]}]"] | +| title | guidance | is_list | required | type | +|:-------------|:-----------|:----------|:-----------|:----------------------------------------------------------------------------------------------------| +| revision url | | False | True | ["Url[{'anyOf': [{'format': 'uri', 'minLength': 1, 'type': 'string'}, {'type': 'null'}]}]", 'null'] | Examples: diff --git a/docs/GWDM/2.0.structure.json b/docs/GWDM/2.0.structure.json index 09ab25e..e7a7c47 100644 --- a/docs/GWDM/2.0.structure.json +++ b/docs/GWDM/2.0.structure.json @@ -102,10 +102,11 @@ "https://api.service.nhs.uk/health-research-data-catalogue/datasetrevisions/841f7da2-b018-41f6-b4ae-2e0aadab6561" ], "type": [ - "Url[{'anyOf': [{'format': 'uri', 'minLength': 1, 'type': 'string'}, {'type': 'null'}]}]" + "Url[{'anyOf': [{'format': 'uri', 'minLength': 1, 'type': 'string'}, {'type': 'null'}]}]", + "null" ], "is_list": false, - "is_optional": false, + "is_optional": true, "subItems": [] } ] diff --git a/docs/HDRUK/3.0.0.form.json b/docs/HDRUK/3.0.0.form.json index 873f941..c05a702 100644 --- a/docs/HDRUK/3.0.0.form.json +++ b/docs/HDRUK/3.0.0.form.json @@ -1841,5 +1841,6 @@ }, "location": "omics.platform" } - ] + ], + "url_regex": "(https?:\\/\\/)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[^\\s]*)?$" } \ No newline at end of file diff --git a/hdr_schemata/models/GWDM/2.0/schema.json b/hdr_schemata/models/GWDM/2.0/schema.json index 1453e23..809db11 100644 --- a/hdr_schemata/models/GWDM/2.0/schema.json +++ b/hdr_schemata/models/GWDM/2.0/schema.json @@ -1368,9 +1368,12 @@ "type": "string" }, "url": { - "allOf": [ + "anyOf": [ { "$ref": "#/$defs/Url" + }, + { + "type": "null" } ], "description": "Some url with a reference to the record of a previous version of this dataset", diff --git a/hdr_schemata/models/GWDM/v2_0/Revision.py b/hdr_schemata/models/GWDM/v2_0/Revision.py index 4ae6e01..96a04cd 100644 --- a/hdr_schemata/models/GWDM/v2_0/Revision.py +++ b/hdr_schemata/models/GWDM/v2_0/Revision.py @@ -1,5 +1,6 @@ from pydantic import AnyUrl, BaseModel, EmailStr, Field, constr from hdr_schemata.definitions.HDRUK import * +from typing import Optional from .annotations import annotations @@ -13,7 +14,7 @@ class Revision(BaseModel): **an.version.__dict__, ) - url: Url = Field( + url: Optional[Url] = Field( ..., **an.url.__dict__, ) diff --git a/hdr_schemata/utils/create_markdown.py b/hdr_schemata/utils/create_markdown.py index b060d26..4fcc695 100644 --- a/hdr_schemata/utils/create_markdown.py +++ b/hdr_schemata/utils/create_markdown.py @@ -219,6 +219,7 @@ def remove_types(data): form = {} form["schema_fields"] = [] + form["url_regex"] = "(https?:\/\/)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?$" form_structure(structure, form) with open(f"{path}/{name}.form.json", "w") as f: json.dump(form, f, indent=6) From b515134272718ba17f0a24e3220889dae418d61a Mon Sep 17 00:00:00 2001 From: Branwen Snelling Date: Fri, 30 Aug 2024 13:53:11 +0100 Subject: [PATCH 2/2] update regex pattern --- docs/HDRUK/3.0.0.form.json | 2 +- hdr_schemata/utils/create_markdown.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/HDRUK/3.0.0.form.json b/docs/HDRUK/3.0.0.form.json index c05a702..258aa93 100644 --- a/docs/HDRUK/3.0.0.form.json +++ b/docs/HDRUK/3.0.0.form.json @@ -1842,5 +1842,5 @@ "location": "omics.platform" } ], - "url_regex": "(https?:\\/\\/)?([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(:\\d+)?(\\/[^\\s]*)?$" + "url_regex": "^\\s*((https?:\\/\\/)*([a-zA-Z0-9-]+\\.?)+[a-zA-Z]{2,}(:\\d+)?(\\/[^\\s]*)?(\n)?)+$" } \ No newline at end of file diff --git a/hdr_schemata/utils/create_markdown.py b/hdr_schemata/utils/create_markdown.py index 4fcc695..c339e10 100644 --- a/hdr_schemata/utils/create_markdown.py +++ b/hdr_schemata/utils/create_markdown.py @@ -219,7 +219,7 @@ def remove_types(data): form = {} form["schema_fields"] = [] - form["url_regex"] = "(https?:\/\/)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?$" + form["url_regex"] = "^\s*((https?:\/\/)*([a-zA-Z0-9-]+\.?)+[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?(\n)?)+$" form_structure(structure, form) with open(f"{path}/{name}.form.json", "w") as f: json.dump(form, f, indent=6)