@@ -86,7 +86,8 @@ class _ViewNotRequired:
8686 __VIEW_NOREQ__ = 1
8787
8888
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 ()
9091 if not isinstance (vbody_types , dict ):
9192 raise InvalidBodyError (
9293 f"__view_body__ should return a dict, not { type (vbody_types )} " , # noqa
@@ -106,8 +107,8 @@ def _format_body(vbody_types: dict) -> list[TypeInfo]:
106107
107108 if isinstance (raw_v , BodyParam ):
108109 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 ) :
111112 v = get_args (raw_v )
112113 default = _ViewNotRequired
113114
@@ -139,6 +140,8 @@ def _build_type_codes(inp: Iterable[type[ValueType]]) -> list[TypeInfo]:
139140 body = get_type_hints (tp )
140141 except KeyError :
141142 body = tp .__annotations__
143+
144+ opt = getattr (tp , "__optional_keys__" , None )
142145
143146 class _Transport :
144147 @staticmethod
@@ -149,7 +152,7 @@ def __view_construct__(**kwargs):
149152 (
150153 TYPECODE_CLASS ,
151154 _Transport ,
152- _format_body (body ),
155+ _format_body (body , not_required = opt ),
153156 ),
154157 )
155158 continue
0 commit comments