Skip to content

Commit

Permalink
Migrate the use of BaseModel.schema and BaseModel.schema_json to …
Browse files Browse the repository at this point in the history
…`BaseModel.model_json_schema`
  • Loading branch information
candleindark committed Dec 5, 2023
1 parent b9604f5 commit 14b0d16
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions dandischema/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def test_types(enumtype: Type[Enum], values: Dict[str, str]) -> None:


def test_autogenerated_titles() -> None:
schema = Asset.schema()
schema = Asset.model_json_schema()
assert schema["title"] == "Asset"
assert schema["properties"]["schemaVersion"]["title"] == "Schema Version"
assert schema["definitions"]["PropertyValue"]["title"] == "Property Value"
Expand Down Expand Up @@ -615,7 +615,7 @@ def test_resource() -> None:


def test_basetype() -> None:
props = json.loads(BaseType.schema_json())["properties"]
props = json.loads(json.dumps(BaseType.model_json_schema()))["properties"]
identifier = props["identifier"]
assert "anyOf" not in identifier
assert identifier.get("maxLength") == 1000
Expand All @@ -624,13 +624,15 @@ def test_basetype() -> None:


def test_https_regex() -> None:
props = json.loads(Affiliation.schema_json())["properties"]["identifier"]
props = json.loads(json.dumps(Affiliation.model_json_schema()))["properties"][
"identifier"
]
assert props["format"] == "uri"
assert props.get("maxLength") == 1000


def test_schemakey_in_required() -> None:
props = json.loads(Affiliation.schema_json())["required"]
props = json.loads(json.dumps(Affiliation.model_json_schema()))["required"]
assert "schemaKey" in props


Expand All @@ -645,9 +647,9 @@ def test_propertyvalue_valid() -> None:


def test_propertyvalue_json() -> None:
reqprops = json.loads(PropertyValue.schema_json())["definitions"]["PropertyValue"][
"required"
]
reqprops = json.loads(json.dumps(PropertyValue.model_json_schema()))["definitions"][
"PropertyValue"
]["required"]
assert "value" == reqprops[1]


Expand Down

0 comments on commit 14b0d16

Please sign in to comment.