Skip to content

Commit c60cd46

Browse files
committed
updating common
1 parent 8ae7532 commit c60cd46

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

api/specs/web-server/_common.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,20 @@
3030

3131

3232
def _create_json_type(**schema_extras):
33-
class _Json(str):
33+
# FIXME: upgrade this to pydnatic v2 protocols
34+
class _JsonStr(str):
3435
__slots__ = ()
3536

36-
# @classmethod
37-
# def __modify_schema__(cls, field_schema: dict[str, Any]) -> None:
38-
# # openapi.json schema is corrected here
39-
# field_schema.update(
40-
# type="string",
41-
# format="json-string" # NOTE: we need to get rid of openapi-core in web-server before using this!
42-
# )
43-
# if schema_extras:
44-
# field_schema.update(schema_extras)
37+
@classmethod
38+
def __get_pydantic_json_schema__(cls, schema: dict[str, Any]) -> dict[str, Any]:
39+
# Update the schema with custom type and format
40+
schema.update(type="string", format="json-string", **schema_extras)
41+
return schema
4542

46-
return _Json
43+
return _JsonStr
4744

4845

49-
def replace_basemodel_in_annotation(annotation, new_type):
46+
def _replace_basemodel_in_annotation(annotation, new_type):
5047
origin = get_origin(annotation)
5148

5249
# Handle Annotated
@@ -63,7 +60,7 @@ def replace_basemodel_in_annotation(annotation, new_type):
6360
# Handle Optionals, Unions, or other generic types
6461
if origin in (Optional, Union, list, dict, tuple): # Extendable for other generics
6562
new_args = tuple(
66-
replace_basemodel_in_annotation(arg, new_type)
63+
_replace_basemodel_in_annotation(arg, new_type)
6764
for arg in get_args(annotation)
6865
)
6966
return origin[new_args]
@@ -90,13 +87,14 @@ def as_query(model_class: type[BaseModel]) -> type[BaseModel]:
9087
"json_schema_extra": field_info.json_schema_extra or {},
9188
}
9289

93-
json_field_type = _create_json_type(
94-
description=query_kwargs["description"],
95-
example=query_kwargs.get("json_schema_extra", {}).get("example_json"),
96-
)
90+
json_field_type = str
91+
# _create_json_type(
92+
# description=query_kwargs["description"],
93+
# example=query_kwargs.get("json_schema_extra", {}).get("example_json"),
94+
# )
9795

98-
annotation = replace_basemodel_in_annotation(
99-
field_info.annotation, new_type=str
96+
annotation = _replace_basemodel_in_annotation(
97+
field_info.annotation, new_type=json_field_type
10098
)
10199

102100
if annotation != field_info.annotation:

0 commit comments

Comments
 (0)