[Python] How to properly generate a documentation with Swagger for Flask

Discussão em 'Python' iniciado por Stack, Junho 24, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to ask how to generate a proper documentation with Swagger for Flask. I have tried many libraries like flasgger, 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 follows:

    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 inconvenient for me to generate it manually by writing a yaml file. I would like to use the marshmallow schemas if possible

    Continue reading...

Compartilhe esta Página