Skip to content

Commit e5fce74

Browse files
committed
add ResolvedGenerateJsonSchema
1 parent b585b96 commit e5fce74

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
See how is used to validate input/output content-schemas of service models
77
"""
8+
89
# SEE possible enhancements in https://github.com/ITISFoundation/osparc-simcore/issues/3008
910

1011

@@ -13,8 +14,11 @@
1314
from copy import deepcopy
1415
from typing import Any
1516

17+
import jsonref
1618
import jsonschema
1719
from jsonschema import validators
20+
from pydantic.json_schema import GenerateJsonSchema, JsonSchemaMode, JsonSchemaValue
21+
from pydantic_core import CoreSchema
1822

1923
# ERRORS
2024

@@ -92,6 +96,13 @@ def any_ref_key(obj):
9296
return False
9397

9498

99+
class ResolvedGenerateJsonSchema(GenerateJsonSchema):
100+
def generate(self, schema: CoreSchema, mode: JsonSchemaMode) -> JsonSchemaValue:
101+
schema_value = super().generate(schema=schema, mode=mode)
102+
schema_value = jsonref.replace_refs(schema_value)
103+
return JsonSchemaValue(schema_value)
104+
105+
95106
__all__: tuple[str, ...] = (
96107
"any_ref_key",
97108
"InvalidJsonSchema",

0 commit comments

Comments
 (0)