@@ -118,20 +118,32 @@ class Endpoint:
118
118
header_parameters : Dict [str , Property ] = field (default_factory = dict )
119
119
cookie_parameters : Dict [str , Property ] = field (default_factory = dict )
120
120
responses : List [Response ] = field (default_factory = list )
121
- form_body_class : Optional [Class ] = None
121
+ form_body : Optional [Property ] = None
122
122
json_body : Optional [Property ] = None
123
123
multipart_body : Optional [Property ] = None
124
124
errors : List [ParseError ] = field (default_factory = list )
125
125
used_python_identifiers : Set [PythonIdentifier ] = field (default_factory = set )
126
126
127
127
@staticmethod
128
- def parse_request_form_body (* , body : oai .RequestBody , config : Config ) -> Optional [Class ]:
129
- """Return form_body_reference"""
128
+ def parse_request_form_body (
129
+ * , body : oai .RequestBody , schemas : Schemas , parent_name : str , config : Config
130
+ ) -> Tuple [Union [Property , PropertyError , None ], Schemas ]:
131
+ """Return form_body and updated schemas"""
130
132
body_content = body .content
131
133
form_body = body_content .get ("application/x-www-form-urlencoded" )
132
- if form_body is not None and isinstance (form_body .media_type_schema , oai .Reference ):
133
- return Class .from_string (string = form_body .media_type_schema .ref , config = config )
134
- return None
134
+ if form_body is not None and form_body .media_type_schema is not None :
135
+ prop , schemas = property_from_data (
136
+ name = "data" ,
137
+ required = True ,
138
+ data = form_body .media_type_schema ,
139
+ schemas = schemas ,
140
+ parent_name = parent_name ,
141
+ config = config ,
142
+ )
143
+ if isinstance (prop , ModelProperty ):
144
+ schemas = attr .evolve (schemas , classes_by_name = {** schemas .classes_by_name , prop .class_info .name : prop })
145
+ return prop , schemas
146
+ return None , schemas
135
147
136
148
@staticmethod
137
149
def parse_multipart_body (
@@ -186,7 +198,20 @@ def _add_body(
186
198
if data .requestBody is None or isinstance (data .requestBody , oai .Reference ):
187
199
return endpoint , schemas
188
200
189
- endpoint .form_body_class = Endpoint .parse_request_form_body (body = data .requestBody , config = config )
201
+ form_body , schemas = Endpoint .parse_request_form_body (
202
+ body = data .requestBody , schemas = schemas , parent_name = endpoint .name , config = config
203
+ )
204
+
205
+ if isinstance (form_body , ParseError ):
206
+ return (
207
+ ParseError (
208
+ header = f"Cannot parse form body of endpoint { endpoint .name } " ,
209
+ detail = form_body .detail ,
210
+ data = form_body .data ,
211
+ ),
212
+ schemas ,
213
+ )
214
+
190
215
json_body , schemas = Endpoint .parse_request_json_body (
191
216
body = data .requestBody , schemas = schemas , parent_name = endpoint .name , config = config
192
217
)
@@ -213,8 +238,9 @@ def _add_body(
213
238
schemas ,
214
239
)
215
240
216
- if endpoint .form_body_class :
217
- endpoint .relative_imports .add (import_string_from_class (endpoint .form_body_class , prefix = "...models" ))
241
+ if form_body is not None :
242
+ endpoint .form_body = form_body
243
+ endpoint .relative_imports .update (endpoint .form_body .get_imports (prefix = "..." ))
218
244
if multipart_body is not None :
219
245
endpoint .multipart_body = multipart_body
220
246
endpoint .relative_imports .update (endpoint .multipart_body .get_imports (prefix = "..." ))
@@ -285,9 +311,9 @@ def add_parameters(
285
311
config: User-provided config for overrides within parameters.
286
312
287
313
Returns:
288
- `(result, schemas)` where `result` is either an updated Endpoint containing the parameters or a ParseError
289
- describing what went wrong. `schemas` is an updated version of the `schemas` input, adding any new enums
290
- or classes.
314
+ `(result, schemas, parameters )` where `result` is either an updated Endpoint containing the parameters or a
315
+ ParseError describing what went wrong. `schemas` is an updated version of the `schemas` input, adding any
316
+ new enums or classes. `parameters` is an updated version of the `parameters` input, adding new parameters .
291
317
292
318
See Also:
293
319
- https://swagger.io/docs/specification/describing-parameters/
0 commit comments