Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Bug Fixes
::

* Adjust field tests for Python 3.14 (``staticmethod`` around ``functools.partial`` used as a class attribute). [python-restx]
* ``Api.init_app(app, version=...)`` now overrides the version supplied to ``Api()`` (#119) [jbbqqf]

.. _section-1.3.1:
1.3.1
Expand Down
4 changes: 4 additions & 0 deletions flask_restx/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def init_app(self, app, **kwargs):
>>> api.init_app(app)

:param flask.Flask app: the Flask application object
:param str version: The API version (used in Swagger documentation)
:param str title: The API title (used in Swagger documentation)
:param str description: The API description (used in Swagger documentation)
:param str terms_url: The API terms page URL (used in Swagger documentation)
Expand All @@ -219,6 +220,9 @@ def init_app(self, app, **kwargs):
reverse proxy.
"""
self.app = app
# version is set in __init__ but used to be dropped here, leaving the
# Swagger info.version stuck on the constructor's default — see #119.
self.version = kwargs.get("version", self.version)
self.title = kwargs.get("title", self.title)
self.description = kwargs.get("description", self.description)
self.terms_url = kwargs.get("terms_url", self.terms_url)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ def test_specs_endpoint_not_added(self, app):
assert "specs" not in api.endpoints
assert "specs" not in app.view_functions

def test_init_app_overrides_version(self, app):
# init_app() should propagate the version kwarg the same way it
# already propagates title/description (see #119). Prior to the
# fix, the version supplied to init_app() was silently dropped,
# so the Swagger "info.version" kept the constructor's value.
api = restx.Api(version="1.0")
api.init_app(app, version="2.5")
assert api.version == "2.5"
with app.test_client() as client:
spec = client.get("/swagger.json").get_json()
assert spec["info"]["version"] == "2.5"

def test_specs_endpoint_not_found_if_not_added(self, app, client):
api = restx.Api()
api.init_app(app, add_specs=False)
Expand Down