Skip to content

Version 2.1.0

Compare
Choose a tag to compare
@greyli greyli released this 17 Dec 09:01
· 42 commits to main since this release
f23495b

Major features

Support adding decorators to the openapi endpoints

by @FarmerChillax in #508

You can the newly added config keys to add auth protect to the OpenAPI endpoints:

app.config['SPEC_DECORATORS'] = [app.auth_required(auth)]
app.config['DOCS_DECORATORS'] = [app.auth_required(auth)]

See the complete example here: https://github.com/apiflask/apiflask/blob/main/examples/openapi/custom_decorators/app.py

Allow adding multiple media types for a response

by @ricardogsilva in #495

@app.get("/pets/<int:pet_id>")
@app.input(Accept, location="headers")
@app.output(PetOut)  # still have a main response of media type 'application/json'
@app.doc(responses={
    200: {
        'description': 'Return the resource in either JSON or HTML',
        'content': {
            'text/html': {}  # have an additional media type for the main response
        }
    }
})
def get_pet(pet_id, headers_data):
    pet = pets[pet_id]
    # depending on the content of the `Accept` header we may return JSON or HTML
    if "html" in headers_data.get('accept'):
        result = render_template('pets/pet-detail.j2.html', pet=pet)
    else:
        result = pet
    return result

Support adding response headers schema

by @uncle-lv in #511

The app.output decorator now accepts a headers argument:

@app.output(PetSchema, headers=MyHeaderSchema)
def hello():
    pass

Add file validators FileSize and FileType for File field

by @uncle-lv in #485

from apiflask.validators import FileType, FileSize

class Image(Schema):
    image = File(validate=[FileType(['.png', '.jpg', '.jpeg', '.gif']), FileSize(max='5 MB')])

See the complete example here: https://github.com/apiflask/apiflask/blob/main/examples/file_upload/app.py

What's Changed

New Contributors

Full Changelog: 2.0.2...2.1.0