-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Upload field to document mutipart file upload
Requires unreleased apispec 3.0 and marshmallow-code/apispec#497
- Loading branch information
Showing
4 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"""Custom fields""" | ||
|
||
import marshmallow as ma | ||
|
||
|
||
class Upload(ma.fields.Field): | ||
"""File upload field""" | ||
def __init__(self, format='binary', **kwargs): | ||
self.format = format | ||
super().__init__(**kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""Custom field properties functions""" | ||
from flask_rest_api.fields import Upload | ||
|
||
|
||
def uploadfield2properties(self, field, **kwargs): | ||
"""Document Upload field""" | ||
ret = {} | ||
if isinstance(field, Upload): | ||
if self.openapi_version.major < 3: | ||
ret['type'] = 'file' | ||
else: | ||
ret['type'] = 'string' | ||
ret['format'] = field.format | ||
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters