Releases: apiflask/apiflask
Version 2.1.1
What's Changed
- Fix syntax error in usage.md by @uncle-lv in #518
- Fix typos in docs and docstrings by @GuodongH in #521
- Add a tip for
auth.current_user
by @uncle-lv in #520 - Update pyupgrade; use --py38-plus by @sloria in #530
- Add Python 3.12 classifier by @sloria in #529
- fix: correct the return type of abort() by @frostming in #533
- Remove override of set_class in Schema by @sloria in #531
- Reuse the File, Config field, and file-related validators from flask-marshmallow by @uncle-lv in #543
- Add support for a --quiet flag to the flask spec command by @tsokalski in #550
- Fix spec command for complex data types by @tsokalski in #549
New Contributors
- @sloria made their first contribution in #530
- @frostming made their first contribution in #533
Full Changelog: 2.1.0...2.1.1
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
Version 2.0.2
What's Changed
- Loosen Flask version requirement to >= 2 and set up test for minimum dependency versions by @wlach in #479
- Add example application for file uploading by @uncle-lv in #476
- Fix typos in docs by @guspan-tanadi in #475
- Refine the basic usage chapter by @greyli in #471
- Fix token auth example by @greyli in #472
New Contributors
- @guspan-tanadi made their first contribution in #475
- @uncle-lv made their first contribution in #476
- @wlach made their first contribution in #479
Full Changelog: 2.0.1...2.0.2
Version 2.0.1
What's Changed
- Fix typing and documentation for
responses
parameter ondoc
decorator by @tsokalski in #467 - Add
Config
field by @greyli in #469
Example usage:
from apiflask import APIFlask, Schema
from apiflask.fields import Config
app = APIFlask(__name__)
app.config['API_TITLE'] = 'Pet API'
class FooSchema(Schema):
title = Config('API_TITLE')
New Contributors
- @tsokalski made their first contribution in #467
Full Changelog: 2.0.0...2.0.1
Version 2.0.0
A new major release!
From APIFlask 2.0.0, all the arguments passed to the view function are keyword arguments. The data passed with the input decorator will be a keyword argument named {location}_data
. For example, the name for the JSON input will be json_data
:
@app.post('/pets')
@app.input(PetQuery, location='query')
@app.input(PetIn) # equals to app.input(PetIn, location='json')
def create_pet(query_data, json_data):
pass
You can set a custom argument name with arg_name
:
@app.post('/pets')
@app.input(PetQuery, location='query') # query_data
@app.input(PetIn, arg_name='pet') # pet
def create_pet(query_data, pet):
pass
Other enhancements and changes:
- Add
FileSchema
to generate an OpenAPI file response (#447). - Support using
{}
to represent not only empty body (204) but also empty schema. Using{}
orEmptySchema
will not set the status code to 204 anymore (#453). - Support setting a complete response OpenAPI spec through the
app.doc(responses)
parameter (i.e.responses={400: {'description': '', 'content': ...}}
) (#327).
See the changelog for the full changes: https://apiflask.com/changelog/#version-200
See the migration guide when you start to migrate to 2.x: https://apiflask.com/migration_guide/#migrate-to-apiflask-2x
Version 1.3.1
A new bugfix release!
- Fix typos in openapi.md by @pamelafox in #417
- Fix PyYAML import error by @greyli in #420
New Contributors
- @pamelafox made their first contribution in #417
Full Changelog: 1.3.0...1.3.1
Version 1.3.0
What's New
There are three new features in this release.
from apiflask import APIFlask
app = APIFlask(__name__)
app.config['SPEC_PROCESSOR_PASS_OBJECT'] = True
class FooSchema(Schema):
id = Integer()
@app.spec_processor
def update_spec(spec):
spec.title = 'Updated Title'
spec.components.schema('Foo', schema=FooSchema) # add a schema manually
return spec
auth = HTTPTokenAuth(header="X-Example-Key", security_scheme_name="api_token")
Generated spec:
"securitySchemes":{"api_token":{"in":"header","name":"X-Example-Key","type":"apiKey"}}
@app.post('/image')
@app.output(ImageOutSchema, content_type='image/png')
def get_image():
pass
Full Changelog: 1.2.3...1.3.0
Version 1.2.3
What's Changed
Full Changelog: 1.2.2...1.2.3
Version 1.2.2
What's Changed
- Remove the validation of input location by @mmdbalkhi in #397
- Support passing
Function
type config toSWAGGER_UI_CONFIG
by @tkzt in #402 - Fix the not-iterable exception occurred when directly returning a custom class by @tkzt in #400
- Update requirements by @greyli in #404
Full Changelog: 1.2.1...1.2.2
Version 1.2.1
APIFlask 1.2.1 add the support to generate the servers
field automatically. It's useful when you run your application behind the reverse proxy with a prefix URL.
See the newly added docs for more details: Running the application behind a reverse proxy
Notice that the servers
will not be set when the request context is unavailable (for example, generating the spec with the flask spec
command).