Skip to content

Commit 264f767

Browse files
authored
Merge branch 'master' into mai/upgrade-catalog
2 parents 15d81e3 + 42476f3 commit 264f767

File tree

51 files changed

+1637
-606
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1637
-606
lines changed

api/specs/director/schemas/scripts/create_node-meta-schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
from pathlib import Path
99

1010
import jsonref
11+
from common_library.json_serialization import json_dumps
1112
from models_library.services import ServiceMetaDataPublished
1213

1314
CURRENT_DIR = Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent
1415

1516

1617
if __name__ == "__main__":
1718
with Path.open(CURRENT_DIR.parent / "node-meta-v0.0.1-pydantic.json", "w") as f:
18-
schema = ServiceMetaDataPublished.schema_json()
19+
schema = json_dumps(ServiceMetaDataPublished.model_json_schema())
1920
schema_without_ref = jsonref.loads(schema)
2021

2122
json.dump(schema_without_ref, f, indent=2)

api/specs/director/schemas/scripts/create_project-schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pathlib import Path
99

1010
import jsonref
11+
from common_library.json_serialization import json_dumps
1112
from models_library.projects import Project
1213

1314
CURRENT_DIR = Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent
@@ -17,7 +18,7 @@
1718
with Path.open(
1819
CURRENT_DIR.parent / "common/schemas/project-v0.0.1-pydantic.json", "w"
1920
) as f:
20-
schema = Project.schema_json()
21+
schema = json_dumps(Project.model_json_schema())
2122
schema_without_ref = jsonref.loads(schema)
2223

2324
json.dump(schema_without_ref, f, indent=2)

packages/models-library/Makefile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,6 @@ tests-ci: ## runs unit tests [ci-mode]
4949
-m "not heavy_load" \
5050
$(CURDIR)/tests
5151

52-
.PHONY: project-jsonschema.ignore.json
53-
project-jsonschema.ignore.json: ## creates project-v0.0.1.json for DEV purposes
54-
python3 -c "from models_library.projects import Project; print(Project.schema_json(indent=2))" > $@
55-
56-
.PHONY: service-jsonschema.ignore.json
57-
node-meta-jsonschema.ignore.json: ## creates node-meta-v0.0.1.json for DEV purposes
58-
python3 -c "from models_library.services import ServiceDockerData as cls; print(cls.schema_json(indent=2))" > $@
5952

6053
DOCKER_API_VERSION ?= 1.41
6154
.PHONY: docker_rest_api.py

packages/models-library/src/models_library/function_services_catalog/services/iter_sensitivity.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
from copy import deepcopy
33
from typing import Any
44

5-
from pydantic import schema_of
5+
from pydantic import TypeAdapter
66

77
from ...projects_nodes import OutputID, OutputsDict
88
from ...services import ServiceMetaDataPublished, ServiceType
99
from ...services_constants import LATEST_INTEGRATION_VERSION
1010
from .._key_labels import FUNCTION_SERVICE_KEY_PREFIX
1111
from .._utils import EN, OM, FunctionServices, create_fake_thumbnail_url
1212

13-
LIST_NUMBERS_SCHEMA: dict[str, Any] = schema_of(list[float], title="list[number]")
13+
LIST_NUMBERS_SCHEMA: dict[str, Any] = {
14+
**TypeAdapter(list[float]).json_schema(),
15+
"title": "list[number]",
16+
}
1417

1518

1619
META = ServiceMetaDataPublished.model_validate(

packages/models-library/src/models_library/utils/common_validators.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class MyModel(BaseModel):
2222

2323
from common_library.json_serialization import json_loads
2424
from orjson import JSONDecodeError
25+
from pydantic import BaseModel
2526

2627

2728
def empty_str_to_none_pre_validator(value: Any):
@@ -102,8 +103,8 @@ def create__check_only_one_is_set__root_validator(alternative_field_names: list[
102103
SEE test_uid_or_email_are_set.py for more details
103104
"""
104105

105-
def _validator(cls, values):
106-
assert set(alternative_field_names).issubset(cls.__fields__) # nosec
106+
def _validator(cls: type[BaseModel], values):
107+
assert set(alternative_field_names).issubset(cls.model_fields) # nosec
107108

108109
got = {
109110
field_name: getattr(values, field_name)

packages/models-library/src/models_library/utils/services_io.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22
from copy import deepcopy
33
from typing import Any, Literal
44

5-
from pydantic import schema_of
5+
from pydantic import TypeAdapter
66

77
from ..services import ServiceInput, ServiceOutput
88
from ..services_regex import PROPERTY_TYPE_TO_PYTHON_TYPE_MAP
99

1010
PortKindStr = Literal["input", "output"]
1111
JsonSchemaDict = dict[str, Any]
1212

13+
1314
_PROPERTY_TYPE_TO_SCHEMAS = {
14-
property_type: schema_of(python_type, title=property_type.capitalize())
15+
property_type: {
16+
**TypeAdapter(python_type).json_schema(),
17+
"title": property_type.capitalize(),
18+
}
1519
for property_type, python_type in PROPERTY_TYPE_TO_PYTHON_TYPE_MAP.items()
1620
}
1721

packages/models-library/tests/test__models_fit_schemas.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# pylint:disable=unused-argument
33
# pylint:disable=redefined-outer-name
44
# pylint:disable=protected-access
5-
import json
65
from collections.abc import Callable
76

87
import pytest
@@ -28,7 +27,7 @@ def test_generated_schema_same_as_original(
2827
# TODO: create instead a fixture that returns a Callable and do these checks
2928
# on separate test_* files that follow the same package submodule's hierarchy
3029
#
31-
generated_schema = json.loads(pydantic_model.schema_json(indent=2))
30+
generated_schema = pydantic_model.model_json_schema()
3231
original_schema = json_schema_dict(original_json_schema)
3332

3433
# NOTE: A change is considered an addition when the destination schema has become more permissive relative to the source schema. For example {"type": "string"} -> {"type": ["string", "number"]}.

packages/models-library/tests/test__pydantic_models.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
from typing import Any, Union, get_args, get_origin
1010

1111
import pytest
12+
from common_library.json_serialization import json_dumps
1213
from models_library.projects_nodes import InputTypes, OutputTypes
1314
from models_library.projects_nodes_io import SimCoreFileLink
14-
from pydantic import BaseModel, Field, ValidationError, schema_json_of
15+
from pydantic import BaseModel, Field, TypeAdapter, ValidationError
1516
from pydantic.types import Json
1617
from pydantic.version import version_short
1718

@@ -37,7 +38,9 @@ class ArgumentAnnotation(BaseModel):
3738
data_schema: Json
3839

3940
# notice that this is a raw string!
40-
jsonschema_of_x = schema_json_of(list[int], title="schema[x]")
41+
jsonschema_of_x = json_dumps(
42+
{**TypeAdapter(list[int]).json_schema(), "title": "schema[x]"}
43+
)
4144
assert isinstance(jsonschema_of_x, str)
4245

4346
x_annotation = ArgumentAnnotation(name="x", data_schema=jsonschema_of_x)

packages/models-library/tests/test_service_settings_labels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pprint import pformat
99
from typing import Any, Final, NamedTuple
1010

11+
import pydantic_core
1112
import pytest
1213
from models_library.basic_types import PortInt
1314
from models_library.osparc_variable_identifier import (
@@ -32,7 +33,6 @@
3233
from models_library.services_resources import DEFAULT_SINGLE_SERVICE_NAME
3334
from models_library.utils.string_substitution import TextTemplate
3435
from pydantic import BaseModel, TypeAdapter, ValidationError
35-
from pydantic.json import pydantic_encoder
3636

3737

3838
class _Parametrization(NamedTuple):
@@ -560,7 +560,7 @@ def test_can_parse_labels_with_osparc_identifiers(
560560

561561
def servicelib__json_serialization__json_dumps(obj: Any, **kwargs):
562562
# Analogous to 'models_library.utils.json_serialization.json_dumps'
563-
return json.dumps(obj, default=pydantic_encoder, **kwargs)
563+
return json.dumps(obj, default=pydantic_core.to_jsonable_python, **kwargs)
564564

565565

566566
def test_resolving_some_service_labels_at_load_time(

packages/models-library/tests/test_services_io.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66

77
import yaml
8+
from common_library.json_serialization import json_dumps
89
from models_library.services import ServiceInput, ServiceMetaDataPublished
910
from pint import Unit, UnitRegistry
1011

@@ -13,7 +14,7 @@ def test_service_port_units(tests_data_dir: Path):
1314
ureg = UnitRegistry()
1415

1516
data = yaml.safe_load((tests_data_dir / "metadata-sleeper-2.0.2.yaml").read_text())
16-
print(ServiceMetaDataPublished.schema_json(indent=2))
17+
print(json_dumps(ServiceMetaDataPublished.model_json_schema(), indent=2))
1718

1819
service_meta = ServiceMetaDataPublished.model_validate(data)
1920
assert service_meta.inputs

0 commit comments

Comments
 (0)