Python Connexion — Control "Type" Key In 400 Response Errors
I'm using connexion, a python library for REST API's, with a swagger definition. It's working properly for the actual requests, but when there is an error condition, such as valida
Solution 1:
I have never worked with the underlying framework, but with a quick scan, the module exposes the Flask application constructor. With that, you can define a new app with your swagger file as
app = connexion.App(__name__, specification_dir='swagger/')
and then add custom error handlers. For example for the 400 error you can do
from flask import jsonify
@app.errorhandler(400)
def page_not_found(e):
custom_data = {
'type': 'Advanced type'
# etc
}
return jsonify(custom_data)
Read more about Flask Error handlers here
Solution 2:
I went through this problem also by imputing null to some model property. If you do not want to create an error handler just add the tag
x-nullable: true
in the property that the validation is occurring.
Post a Comment for "Python Connexion — Control "Type" Key In 400 Response Errors"