Version 2.1.0
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
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
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
- Fix typo in fields doc: files -> files_data by @Nekoyue in #499
- Fix Flask version warning by @greyli in #502
- Allow adding multiple media types for a response by @ricardogsilva in #495
- Add more examples of default values, description and example by @sylvain-ri in #505
- feat: response headers schema by @uncle-lv in #511
- Support adding decorators to the openapi endpoints by @FarmerChillax in #508
- Fix base response schema inconsistency issue by @greyli in #515
- Add file validators for File field by @uncle-lv in #485
New Contributors
- @Nekoyue made their first contribution in #499
- @ricardogsilva made their first contribution in #495
- @sylvain-ri made their first contribution in #505
- @FarmerChillax made their first contribution in #508
Full Changelog: 2.0.2...2.1.0