@@ -61,8 +61,10 @@ def from_dict(d: Dict[str, Dict[str, Dict[str, Any]]], /) -> Dict[str, EndpointC
6161 )
6262 responses .append (response )
6363 form_body_reference = None
64+ json_body = None
6465 if "requestBody" in method_data :
65- form_body_reference = Endpoint .parse_request_body (method_data ["requestBody" ])
66+ form_body_reference = Endpoint .parse_request_form_body (method_data ["requestBody" ])
67+ json_body = Endpoint .parse_request_json_body (method_data ["requestBody" ])
6668
6769 endpoint = Endpoint (
6870 path = path ,
@@ -73,6 +75,7 @@ def from_dict(d: Dict[str, Dict[str, Dict[str, Any]]], /) -> Dict[str, EndpointC
7375 path_parameters = path_parameters ,
7476 responses = responses ,
7577 form_body_reference = form_body_reference ,
78+ json_body = json_body ,
7679 requires_security = bool (method_data .get ("security" )),
7780 )
7881
@@ -81,6 +84,14 @@ def from_dict(d: Dict[str, Dict[str, Dict[str, Any]]], /) -> Dict[str, EndpointC
8184 collection .relative_imports .add (
8285 import_string_from_reference (form_body_reference , prefix = "..models" )
8386 )
87+ if (
88+ json_body is not None
89+ and isinstance (json_body , (ListProperty , RefProperty , EnumProperty ))
90+ and json_body .reference is not None
91+ ):
92+ collection .relative_imports .add (
93+ import_string_from_reference (json_body .reference , prefix = "..models" )
94+ )
8495 return endpoints_by_tag
8596
8697
@@ -99,17 +110,27 @@ class Endpoint:
99110 responses : List [Response ]
100111 requires_security : bool
101112 form_body_reference : Optional [Reference ]
113+ json_body : Optional [Property ]
102114
103115 @staticmethod
104- def parse_request_body (body : Dict [str , Any ], / ) -> Optional [Reference ]:
105- """ Return form_body_ref """
116+ def parse_request_form_body (body : Dict [str , Any ], / ) -> Optional [Reference ]:
117+ """ Return form_body_reference """
106118 form_body_reference = None
107119 body_content = body ["content" ]
108120 form_body = body_content .get ("application/x-www-form-urlencoded" )
109121 if form_body :
110122 form_body_reference = Reference (form_body ["schema" ]["$ref" ])
111123 return form_body_reference
112124
125+ @staticmethod
126+ def parse_request_json_body (body : Dict [str , Any ], / ) -> Optional [Property ]:
127+ """ Return json_body """
128+ body_content = body ["content" ]
129+ json_body = body_content .get ("application/json" )
130+ if json_body :
131+ return property_from_dict ("json_body" , required = True , data = json_body ["schema" ])
132+ return None
133+
113134
114135@dataclass
115136class Schema :
0 commit comments