@@ -86,7 +86,8 @@ class _ViewNotRequired:
86
86
__VIEW_NOREQ__ = 1
87
87
88
88
89
- def _format_body (vbody_types : dict ) -> list [TypeInfo ]:
89
+ def _format_body (vbody_types : dict , * , not_required : set [str ] | None = None ) -> list [TypeInfo ]:
90
+ not_required = not_required or set ()
90
91
if not isinstance (vbody_types , dict ):
91
92
raise InvalidBodyError (
92
93
f"__view_body__ should return a dict, not { type (vbody_types )} " , # noqa
@@ -106,8 +107,8 @@ def _format_body(vbody_types: dict) -> list[TypeInfo]:
106
107
107
108
if isinstance (raw_v , BodyParam ):
108
109
default = raw_v .default
109
-
110
- if getattr (raw_v , "__origin__" , None ) in _NOT_REQUIRED_TYPES :
110
+
111
+ if ( getattr (raw_v , "__origin__" , None ) in _NOT_REQUIRED_TYPES ) or ( k in not_required ) :
111
112
v = get_args (raw_v )
112
113
default = _ViewNotRequired
113
114
@@ -139,6 +140,8 @@ def _build_type_codes(inp: Iterable[type[ValueType]]) -> list[TypeInfo]:
139
140
body = get_type_hints (tp )
140
141
except KeyError :
141
142
body = tp .__annotations__
143
+
144
+ opt = getattr (tp , "__optional_keys__" , None )
142
145
143
146
class _Transport :
144
147
@staticmethod
@@ -149,7 +152,7 @@ def __view_construct__(**kwargs):
149
152
(
150
153
TYPECODE_CLASS ,
151
154
_Transport ,
152
- _format_body (body ),
155
+ _format_body (body , not_required = opt ),
153
156
),
154
157
)
155
158
continue
0 commit comments