From cd52d81d3a4a7780eb3a1e543e46d6c1f7876654 Mon Sep 17 00:00:00 2001 From: Michael Bukachi Date: Sun, 12 May 2019 11:54:15 +0300 Subject: [PATCH 1/3] feat: Add config option to disable models display in swagger This commit adds a `SWAGGER_DEFAULT_MODELS_EXPANSION_DEPTH` config option which corresponds to the `defaultModelsExpandDepth` in swagger which allow the showing/hiding of models in the swagger documentation --- flask_restplus/templates/swagger-ui.html | 3 ++- tests/test_apidoc.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/flask_restplus/templates/swagger-ui.html b/flask_restplus/templates/swagger-ui.html index cecce6ab..532169d2 100644 --- a/flask_restplus/templates/swagger-ui.html +++ b/flask_restplus/templates/swagger-ui.html @@ -65,7 +65,8 @@ {%- endif %} displayOperationId: {{ config.SWAGGER_UI_OPERATION_ID|default(False)|tojson }}, displayRequestDuration: {{ config.SWAGGER_UI_REQUEST_DURATION|default(False)|tojson }}, - docExpansion: "{{ config.SWAGGER_UI_DOC_EXPANSION | default('none') }}" + docExpansion: "{{ config.SWAGGER_UI_DOC_EXPANSION | default('none') }}", + defaultModelsExpandDepth: {{ config.SWAGGER_DEFAULT_MODELS_EXPANSION_DEPTH | default(1) }} }) {% if config.SWAGGER_UI_OAUTH_CLIENT_ID -%} diff --git a/tests/test_apidoc.py b/tests/test_apidoc.py index 1f0a9bca..7f26138a 100644 --- a/tests/test_apidoc.py +++ b/tests/test_apidoc.py @@ -63,6 +63,16 @@ def test_apidoc_doc_expansion_parameter(self, app, client): response = client.get(url_for('doc')) assert 'docExpansion: "full"' in str(response.data) + def test_apidoc_defualt_models_expansion_depth_parameter(self, app, client): + restplus.Api(app) + + response = client.get(url_for('doc')) + assert 'defaultModelsExpandDepth: 1' in str(response.data) + + app.config['SWAGGER_DEFAULT_MODELS_EXPANSION_DEPTH'] = -1 + response = client.get(url_for('doc')) + assert 'defaultModelsExpandDepth: -1' in str(response.data) + def test_apidoc_doc_display_operation_id(self, app, client): restplus.Api(app) From 5525e563ec3a8c880603dc1c0831a4d30d1b11e7 Mon Sep 17 00:00:00 2001 From: Michael Bukachi Date: Sun, 12 May 2019 12:06:46 +0300 Subject: [PATCH 2/3] doc: Add documentation for commit cd52d81d --- doc/swagger.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/swagger.rst b/doc/swagger.rst index a686a263..f5bace22 100644 --- a/doc/swagger.rst +++ b/doc/swagger.rst @@ -905,6 +905,21 @@ setting (``'none'``, ``'list'`` or ``'full'``): api = Api(app) + +By default, models are shown at the bottom. You can show/hide the models in the documentation with the +``config.SWAGGER_DEFAULT_MODELS_EXPANSION_DEPTH`` setting (``1``, or ``-1``): + +.. code-block:: python + + from flask import Flask + from flask_restplus import Api + + app = Flask(__name__) + app.config.SWAGGER_DEFAULT_MODELS_EXPANSION_DEPTH = -1 + + api = Api(app) + + By default, operation ID is hidden as well as request duration, you can enable them respectively with: .. code-block:: python From 84a7b681aded9a623d254a27a1fc44002a517ef5 Mon Sep 17 00:00:00 2001 From: Michael Bukachi Date: Sun, 12 May 2019 12:14:26 +0300 Subject: [PATCH 3/3] doc: Update Changelog --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 88b1ba4e..0bc8458b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -11,6 +11,7 @@ Current - Fix `@api.expect(..., validate=False)` decorators for an :class:`Api` where `validate=True` is set on the constructor (:issue:`609`, :pr:`610`) - Ensure `basePath` is always a path - Hide Namespaces with all hidden Resources from Swagger documentation +- Add `SWAGGER_DEFAULT_MODELS_EXPANSION_DEPTH` config option to hide/show models in Swagger documentation 0.12.1 (2018-09-28) -------------------