Skip to content

Commit 41f7205

Browse files
committed
schema_json
1 parent 43861b4 commit 41f7205

File tree

7 files changed

+10
-15
lines changed

7 files changed

+10
-15
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/tests/test__models_fit_schemas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
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
8+
from common_library.json_serialization import json_loads
99
from models_library.projects import Project
1010
from models_library.services import ServiceMetaDataPublished
1111
from pydantic.main import BaseModel
@@ -28,7 +28,7 @@ def test_generated_schema_same_as_original(
2828
# TODO: create instead a fixture that returns a Callable and do these checks
2929
# on separate test_* files that follow the same package submodule's hierarchy
3030
#
31-
generated_schema = json.loads(pydantic_model.schema_json(indent=2))
31+
generated_schema = json_loads(pydantic_model.model_json_schema(), indent=2)
3232
original_schema = json_schema_dict(original_json_schema)
3333

3434
# 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_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

packages/pytest-simcore/src/pytest_simcore/helpers/faker_catalog.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def create_service_out2(**overrides):
3232
# https://github.com/ITISFoundation/osparc-simcore/blob/master/services/catalog/src/simcore_service_catalog/models/schemas/services.py
3333
#
3434
# docker exec -it $(docker ps --filter="ancestor=local/catalog:development" -q)
35-
# python -c "from simcore_service_catalog.models.schemas.services import ServiceOut;print(ServiceOut.schema_json(indent=2))" > services/catalog/ignore-schema.json
3635
# put file in https://json-schema-faker.js.org/ and get fake output
3736
#
3837

0 commit comments

Comments
 (0)