Question
I'm using the request parser to specify & document an API that expects a (possibly) non-JSON payload in a PUT request, where the Content-Type header specifies the mime type of the body contents. My issue is with the Swagger spec that is generated from the parser arguments.
At the moment, the location parameter to add_argument can only be set to form or json. The first will have the Swagger UI PUT a POST form, instead of a vanilla body, and it sets the Content-Type to application/x-www-form-urlencoded or multipart/form-data in the Swagger API documentation. The second will force the Content-Type to application/json which is not correct either.
Is there a way to have the Swagger UI show that it expects a PUT body without forcing the content type?
Context
Code looks something like this:
blueprint = Blueprint('api', __name__)
api = Api(blueprint)
ns = api.namespace('generate', description='Generator service')
# Register the api blueprint
app.register_blueprint(blueprint, url_prefix='/api')
generate_data_parser = api.parser()
generate_data_parser.add_argument('Content-Type', required=False, default="application/ld+json", help='The MIME type of of the data provided.', location='headers')
# Set location either to json or form, but cannot set to body?
generate_data_parser.add_argument("data", required=True, location="json", help="The data that you want to validate.")
@ns.route('/data', methods=['PUT'], doc={"name": "Generate something cool", "description": "Generate something cool"})
class GenerateData(Resource):
@ns.expect(generate_data_parser)
def put(self):
byte_data = request.data
mime_type = request.headers.get('Content-Type', "application/ld+json")
# DO SOMETHING REALLY INTELLIGENT
return make_response(...)
Question I'm using the request parser to specify & document an API that expects a (possibly) non-JSON payload in a PUT request, where the Content-Type header specifies the mime type of the body contents. My issue is with the Swagger spec that is generated from the parser arguments.
At the moment, the
location
parameter toadd_argument
can only be set toform
orjson
. The first will have the Swagger UI PUT a POST form, instead of a vanilla body, and it sets the Content-Type toapplication/x-www-form-urlencoded
ormultipart/form-data
in the Swagger API documentation. The second will force the Content-Type toapplication/json
which is not correct either.Is there a way to have the Swagger UI show that it expects a PUT body without forcing the content type?
Context Code looks something like this: