Bot releases are hidden (Show)
auth.current_user
by @uncle-lv in https://github.com/apiflask/apiflask/pull/520
Full Changelog: https://github.com/apiflask/apiflask/compare/2.1.0...2.1.1
Published by greyli 10 months ago
by @FarmerChillax in https://github.com/apiflask/apiflask/pull/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
by @ricardogsilva in https://github.com/apiflask/apiflask/pull/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
by @uncle-lv in https://github.com/apiflask/apiflask/pull/511
The app.output
decorator now accepts a headers
argument:
@app.output(PetSchema, headers=MyHeaderSchema)
def hello():
pass
FileSize
and FileType
for File fieldby @uncle-lv in https://github.com/apiflask/apiflask/pull/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
Full Changelog: https://github.com/apiflask/apiflask/compare/2.0.2...2.1.0
Published by greyli about 1 year ago
Full Changelog: https://github.com/apiflask/apiflask/compare/2.0.1...2.0.2
Published by greyli about 1 year ago
responses
parameter on doc
decorator by @tsokalski in https://github.com/apiflask/apiflask/pull/467
Config
field by @greyli in https://github.com/apiflask/apiflask/pull/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')
Full Changelog: https://github.com/apiflask/apiflask/compare/2.0.0...2.0.1
Published by greyli about 1 year ago
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:
FileSchema
to generate an OpenAPI file response (#447).{}
to represent not only empty body (204) but also empty schema. Using {}
or EmptySchema
will not set the status code to 204 anymore (#453).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
Published by greyli over 1 year ago
A new bugfix release!
Full Changelog: https://github.com/apiflask/apiflask/compare/1.3.0...1.3.1
Published by greyli over 1 year ago
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
security_scheme_name
to customize OpenAPI security key by @greyli in https://github.com/apiflask/apiflask/pull/411auth = 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: https://github.com/apiflask/apiflask/compare/1.2.3...1.3.0
Published by greyli over 1 year ago
Full Changelog: https://github.com/apiflask/apiflask/compare/1.2.2...1.2.3
Published by greyli over 1 year ago
Function
type config to SWAGGER_UI_CONFIG
by @tkzt in https://github.com/apiflask/apiflask/pull/402
Full Changelog: https://github.com/apiflask/apiflask/compare/1.2.1...1.2.2
Published by greyli almost 2 years ago
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).
Published by greyli almost 2 years ago
apiflask.views.MethodView
to replace flask.views.MethodView
, raise error ifflask.views.MethodView
(#341)from apiflask.views import MethodView
You can control this with the config key VALIDATION_ERROR_STATUS_CODE
:
app.config['VALIDATION_ERROR_STATUS_CODE'] = 422
Enum
field from marshmallow 3.18.spec_plugins
param to APIFlask
class to support using custom apispec plugins (#349). Thanks @ndawnview_func.view_class
is MethodViewType
in add_url_rule
(#379). Thanks @rod7760flask spec
is deterministicThanks @mmdbalkhi for working on the Persian translation of APIFlask docs.
Published by greyli about 2 years ago
One more bugfix release.
We still need to make a real fix for #341, any help will be appreciated.
Published by greyli about 2 years ago
A bugfix release.
router
setting. Now the default router
option value will be hash
. #339Published by greyli about 2 years ago
A bugfix release for Flask 2.2.
APIFlask
path parameters (#329). Thanks @jeamlandMethodViewType
usages for Flask 2.2 (#335). Thanks @z-t-yPublished by greyli over 2 years ago
A new feature release!
docs_ui
parameter (#308):from apiflask import APIFlask
# available docs_ui values: swagger-ui, redoc, elements, rapidoc, rapipdf
app = APIFlask(__name__, docs_ui='elements')
/docs
by default, and the /redoc
path and the redoc_path
parameter were deprecated and will be removed in 2.0.list
as JSON (#322):@app.route('/')
def index():
return ['this', 'will', 'become', 'JSON']
P.S. This feature will also be available in Flask 2.2.
See the full changelog for more details: https://apiflask.com/changelog/#version-110
Published by greyli over 2 years ago
Another bugfix release.
path
(view_args
) to the valid request location list (issue #301)Published by greyli over 2 years ago
A bugfix release:
app.auth_required
, app.input
, and app.doc
decorators (issue #288). Thanks @jiashuChen!Published by greyli over 2 years ago
APIFlask 1.0 is finally released! 🎉
Retweet the announcement on Twitter to tell your friends this news:
https://twitter.com/apiflask/status/1521869484746702849
Thanks for all your support!
Published by greyli over 2 years ago
This version brings a breaking change:
The four standalone API decorators (i.e. input
, output
, doc
, and auth_required
) were moved to APIFlask
and APIBlueprint classes
. Now access them with your application or blueprint instance:
from apiflask import APIFlask
app = APIFlask(__name__)
@app.get('/')
@app.input(FooSchema) # <-
@app.output(BarSchema) # <-
def hello():
return {'message': 'Hello'}
This makes it possible to access app instance in these decorators so we can support changing corresponding behaviors based on application attributes or configuration variables.
The old standalone decorators were deprecated since 0.12, and will be removed in the 1.0 version. Notice all the usage in the docs/examples are updated, you may want to upgrade APIFlask to update the usage in your app.
The next version will be 1.0.0. Stay tuned!
Published by greyli almost 3 years ago
This version improves the error handling system, you can now write custom error classes based on HTTPError:
from apiflask import HTTPError
class PetNotFound(HTTPError):
status_code = 404
message = 'This pet is missing.'
extra_data = {
'error_code': '2323',
'error_docs': 'https://example.com/docs/missing'
}
@app.get('/pets/<pet_id>')
def get_pet(pet_id):
pets = [1, 2, 3]
if pet_id not in pets:
raise PetNotFound
return {'message': 'Pet'}
See more details in the newly added docs for error handling.