@@ -27,6 +27,7 @@ def camelcase(string):
27
27
"jpeg" : "image/jpeg" ,
28
28
"png" : "image/png" ,
29
29
"gif" : "image/gif" ,
30
+ "form" : "multipart/form-data" ,
30
31
"*/*" : "*/*" ,
31
32
}
32
33
@@ -114,6 +115,8 @@ def __init__(
114
115
if self .location == "path" :
115
116
self .required = True
116
117
118
+ print (f"Parameter: { self .name } { self .location } " )
119
+
117
120
@property
118
121
def datatype (self ):
119
122
"""Return the parameter datatype."""
@@ -171,7 +174,7 @@ def in_request_body(self):
171
174
172
175
:return bool: True if in request body
173
176
"""
174
- if self .location == "body" :
177
+ if self .location in [ "body" , "form" ] :
175
178
return True
176
179
177
180
return False
@@ -289,8 +292,18 @@ def __init__(
289
292
self .parameters = [Parameter (** x ) for x in parameters or []]
290
293
self .responses = [Response (** x ) for x in responses or []]
291
294
self .return_type = return_type
292
- self .accepts = accepts or "*/*"
293
- self .body = {x .name : x .dict () for x in self .parameters if x .in_request_body ()}
295
+ self ._accepts = accepts
296
+ self .request_body_parameters = {x .name : x .dict () for x in self .parameters if x .in_request_body ()}
297
+
298
+ @property
299
+ def accepts (self ):
300
+ """Return accepts type."""
301
+ if self ._accepts :
302
+ return self ._accepts
303
+ if self .has_form ():
304
+ return "form"
305
+
306
+ return "*/*"
294
307
295
308
def binary_body (self ):
296
309
"""Return binary body."""
@@ -306,20 +319,30 @@ def binary_body(self):
306
319
}
307
320
}
308
321
309
- def json_body (self ):
310
- """Return JSON body."""
322
+ def has_form (self ):
323
+ """
324
+ Return whether operation has form data.
325
+
326
+ Return `True` if the operation has form data parameters.
327
+
328
+ :return bool: True if has form data
329
+ """
330
+ return [x for x in self .parameters if x .location == "form" ] != []
331
+
332
+ def body (self ):
333
+ """Return request body."""
311
334
accepts = CONTENT_MAP .get (self .accepts )
312
335
return {
313
336
"description" : self .description ,
314
- "content" : {accepts : {"schema" : {"type" : "object" , "properties" : self .body }}},
337
+ "content" : {accepts : {"schema" : {"type" : "object" , "properties" : self .request_body_parameters }}},
315
338
}
316
339
317
340
def request_body (self ):
318
341
"""Return request body."""
319
- if self .accepts == "binary" :
342
+ if self .accepts in [ "binary" ] :
320
343
return self .binary_body ()
321
344
322
- return self .json_body ()
345
+ return self .body ()
323
346
324
347
def dict (self ):
325
348
"""Return dict of data."""
@@ -331,7 +354,7 @@ def dict(self):
331
354
"parameters" : [x .dict () for x in self .parameters if not x .in_request_body ()],
332
355
"responses" : {x .code : x .dict () for x in self .responses },
333
356
}
334
- if self .body :
357
+ if self .request_body_parameters :
335
358
operation ["requestBody" ] = self .request_body ()
336
359
337
360
return {self .operation : operation }
0 commit comments