Skip to content

Releases: apiflask/apiflask

Version 2.1.1

10 Mar 14:48
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: 2.1.0...2.1.1

Version 2.1.0

17 Dec 09:01
f23495b
Compare
Choose a tag to compare

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

Version 2.0.2

24 Sep 03:06
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: 2.0.1...2.0.2

Version 2.0.1

16 Aug 00:23
Compare
Choose a tag to compare

What's Changed

  • Fix typing and documentation for responses parameter on doc 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

Full Changelog: 2.0.0...2.0.1

Version 2.0.0

26 Jul 00:51
Compare
Choose a tag to compare

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 {} or EmptySchema 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

27 Mar 13:42
Compare
Choose a tag to compare

A new bugfix release!

New Contributors

Full Changelog: 1.3.0...1.3.1

Version 1.3.0

18 Mar 09:11
Compare
Choose a tag to compare

What's New

There are three new features in this release.

  • Support passing APISpec object to spec processor by @greyli in #412
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
  • Add security_scheme_name to customize OpenAPI security key by @greyli in #411
    Example usage:
auth = HTTPTokenAuth(header="X-Example-Key", security_scheme_name="api_token")

Generated spec:

"securitySchemes":{"api_token":{"in":"header","name":"X-Example-Key","type":"apiKey"}}
  • Support customizing the media/content type of the response by @greyli in #413
@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

21 Feb 13:53
Compare
Choose a tag to compare

What's Changed

  • Bypass OpenAPI spec generation for view methods by @greyli in #407

Full Changelog: 1.2.2...1.2.3

Version 1.2.2

18 Feb 08:27
Compare
Choose a tag to compare

What's Changed

  • Remove the validation of input location by @mmdbalkhi in #397
  • Support passing Function type config to SWAGGER_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

15 Jan 04:54
Compare
Choose a tag to compare

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).