Skip to content

Commit 7615a5e

Browse files
committed
WIP
1 parent 3a485c4 commit 7615a5e

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

api/specs/web-server/_common.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33

44
import inspect
5+
import pprint
56
import sys
67
from collections.abc import Callable
78
from pathlib import Path
@@ -32,15 +33,15 @@ def _create_json_type(**schema_extras):
3233
class _Json(str):
3334
__slots__ = ()
3435

35-
@classmethod
36-
def __modify_schema__(cls, field_schema: dict[str, Any]) -> None:
37-
# openapi.json schema is corrected here
38-
field_schema.update(
39-
type="string",
40-
# format="json-string" NOTE: we need to get rid of openapi-core in web-server before using this!
41-
)
42-
if schema_extras:
43-
field_schema.update(schema_extras)
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)
4445

4546
return _Json
4647

@@ -79,8 +80,9 @@ def as_query(model_class: type[BaseModel]) -> type[BaseModel]:
7980
fields = {}
8081
for field_name, field_info in model_class.model_fields.items():
8182

83+
field_default = field_info.default
84+
assert not field_info.default_factory # nosec
8285
query_kwargs = {
83-
"default": field_info.default,
8486
"alias": field_info.alias,
8587
"title": field_info.title,
8688
"description": field_info.description,
@@ -94,18 +96,17 @@ def as_query(model_class: type[BaseModel]) -> type[BaseModel]:
9496
)
9597

9698
annotation = replace_basemodel_in_annotation(
97-
field_info.annotation, new_type=json_field_type
99+
field_info.annotation, new_type=str
98100
)
99101

100102
if annotation != field_info.annotation:
101103
# Complex fields are transformed to Json
102-
query_kwargs["default"] = (
103-
json_dumps(query_kwargs["default"]) if query_kwargs["default"] else None
104-
)
104+
field_default = json_dumps(field_default) if field_default else None
105105

106-
fields[field_name] = (annotation, Query(**query_kwargs))
106+
fields[field_name] = (annotation, Query(default=field_default, **query_kwargs))
107107

108108
new_model_name = f"{model_class.__name__}Query"
109+
pprint.pprint(fields)
109110
return create_model(new_model_name, **fields)
110111

111112

0 commit comments

Comments
 (0)