[FIX] Add monkey-patch for flask-restx swagger multipart form support #713
+126
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change introduces a monkey-patch for the flask-restx
Swagger.serialize_operation
method to force Swagger to use "multipart/form-data" content type for multi-file uploads instead of "application/x-www-form-urlencoded", as required by our application. The patch applies the proposed changes from PR 542 in the flask-restx repository (python-restx/flask-restx#542), which is unlikely to be accepted into the main branch.The monkey-patch includes the following safety measures:
flask_restx.Swagger.serialize_operation
before applying the patch. This prevents potential issues if the underlying library code changes.The patch is applied during application initialization through a new
monkey_patch_flask_restx()
function, which is called in thecreate_app()
setup process. While this is not an ideal solution, the safeguards should sufficiently minimize risk in the absence of upstream support for this behavior.