Skip to content

Document/specify request parser PUT body that is not JSON #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
RinkeHoekstra opened this issue Feb 20, 2020 · 1 comment
Open

Document/specify request parser PUT body that is not JSON #67

RinkeHoekstra opened this issue Feb 20, 2020 · 1 comment
Labels
question Further information is requested

Comments

@RinkeHoekstra
Copy link

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(...)
@RinkeHoekstra RinkeHoekstra added the question Further information is requested label Feb 20, 2020
@RinkeHoekstra
Copy link
Author

(FWIW, I know the request parser is set to be deprecated, but currently the rest of my code relies on it...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant