Monday, 27 March 2023

How to properly generate a documentation with Swagger for Flask

I would like to ask how to generate a proper documentation with Swagger for Flask. I have tried many libraries like flassger, apispec, marshmallow, flask_apispec, etc but I didn't find the best one.

So I have a function here:

@app.route('/test', methods=['POST])
def test_function():
    data = request.get_json()
    validated_data = TestSchema().load(data)
    # Doing something here
    return jsonify({'data': 'success'}), 200

I already have a schema object with marshmallow as follow:

class TestSchema(Schema):
    id = fields.Int(required=True)
    name = fields.Str(required=True)

I want to automatically generate the documentation so that it is easier to know how to call my test API. How can I do this with swagger UI? I'm not really familiar with web programming and APISpec things, so it is inconvenience for me to generate it manually my writing yaml file.



from How to properly generate a documentation with Swagger for Flask

No comments:

Post a Comment