From 6d4baccf08172d98730b81235847c363b04a99d8 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 31 Oct 2024 12:47:57 -0400 Subject: [PATCH 1/4] [DATALAD RUNCMD] Replace Union[Any, List[Any]] with just Any since Any also represents List or anything else really. I thought that it might be used somewhere in the meditor to edit dandiset metadata but it seems that nothing of that type propagated into dandiset metadata so it should not be effected === Do not change lines below === { "chain": [], "cmd": "git-sedi 'Union\\[Any, List\\[Any\\]\\]' Any", "exit": 0, "extra_inputs": [], "inputs": [], "outputs": [], "pwd": "." } ^^^ Do not change lines above ^^^ --- dandischema/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dandischema/models.py b/dandischema/models.py index 20af6198..a883c2e8 100644 --- a/dandischema/models.py +++ b/dandischema/models.py @@ -604,7 +604,7 @@ class PropertyValue(DandiBaseModel): maxValue: Optional[float] = Field(None, json_schema_extra={"nskey": "schema"}) minValue: Optional[float] = Field(None, json_schema_extra={"nskey": "schema"}) unitText: Optional[str] = Field(None, json_schema_extra={"nskey": "schema"}) - value: Union[Any, List[Any]] = Field( + value: Any = Field( None, validate_default=True, json_schema_extra={"nskey": "schema"}, @@ -626,7 +626,7 @@ class PropertyValue(DandiBaseModel): @field_validator("value") @classmethod - def ensure_value(cls, val: Union[Any, List[Any]]) -> Union[Any, List[Any]]: + def ensure_value(cls, val: Any) -> Any: if not val: raise ValueError( "The value field of a PropertyValue cannot be None or empty." From 50b63c0792dab1f3d47f83cda6b1ef7f2b541c85 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 31 Oct 2024 13:52:04 -0400 Subject: [PATCH 2/4] Make identifier singular (remove possibility for a list of identifiers) for Locus and Allele So far I see no values with such data types used at all in dandi archive so we should not break anything An alternative would be to just make it a List[Identifier] always and not bother allowing for the dance of singular-vs-plural. --- dandischema/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dandischema/models.py b/dandischema/models.py index a883c2e8..2360b288 100644 --- a/dandischema/models.py +++ b/dandischema/models.py @@ -1262,7 +1262,7 @@ class PublishActivity(Activity): class Locus(DandiBaseModel): - identifier: Union[Identifier, List[Identifier]] = Field( + identifier: Identifier = Field( description="Identifier for genotyping locus.", json_schema_extra={"nskey": "schema"}, ) @@ -1274,7 +1274,7 @@ class Locus(DandiBaseModel): class Allele(DandiBaseModel): - identifier: Union[Identifier, List[Identifier]] = Field( + identifier: Identifier = Field( description="Identifier for genotyping allele.", json_schema_extra={"nskey": "schema"}, ) From b2205ac62694b3609aeb79ae79f4a15d8b016334 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 31 Oct 2024 14:01:40 -0400 Subject: [PATCH 3/4] Remove possibility for listing multiple GenotypeInfo for "genotype" That would avoid Union of a list with non-multivalued identifier. And we already have data with string value describing the genotype -- it is not really an identifier!!! --- dandischema/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dandischema/models.py b/dandischema/models.py index 2360b288..e8ac37ca 100644 --- a/dandischema/models.py +++ b/dandischema/models.py @@ -1373,7 +1373,7 @@ class Participant(DandiBaseModel): "available. (e.g. from OBI)", json_schema_extra={"nskey": "dandi"}, ) - genotype: Optional[Union[List[GenotypeInfo], Identifier]] = Field( + genotype: Optional[Union[GenotypeInfo, Identifier]] = Field( None, description="Genotype descriptor of participant or subject if available", json_schema_extra={"nskey": "dandi"}, From 5111e31a06da90099ba1d233648970eafbcd7df8 Mon Sep 17 00:00:00 2001 From: Isaac To Date: Tue, 5 Nov 2024 14:08:06 -0800 Subject: [PATCH 4/4] fix: remove JSON customization for `anyOf` elements This eliminate error in validating an `anyOf` element containing a `string` element for example --- dandischema/models.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dandischema/models.py b/dandischema/models.py index e8ac37ca..f328f9bf 100644 --- a/dandischema/models.py +++ b/dandischema/models.py @@ -563,7 +563,6 @@ def __get_pydantic_json_schema__( if value.get("format", None) == "uri": value["maxLength"] = 1000 allOf = value.get("allOf") - anyOf = value.get("anyOf") items = value.get("items") if allOf is not None: if len(allOf) == 1 and "$ref" in allOf[0]: @@ -573,9 +572,6 @@ def __get_pydantic_json_schema__( value["oneOf"] = value["allOf"] value["type"] = "object" del value["allOf"] - if anyOf is not None: - if len(anyOf) > 1 and any(["$ref" in val for val in anyOf]): - value["type"] = "object" if items is not None: anyOf = items.get("anyOf") if (