Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option for showing/hiding models in documentation #644

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Current
- Ensure `basePath` is always a path
- Hide Namespaces with all hidden Resources from Swagger documentation
- Per route Swagger documentation for multiple routes on a ``Resource``
- Add `SWAGGER_DEFAULT_MODELS_EXPANSION_DEPTH` config option to hide/show models in Swagger documentation

0.12.1 (2018-09-28)
-------------------
Expand Down
15 changes: 15 additions & 0 deletions doc/swagger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,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
Expand Down
3 changes: 2 additions & 1 deletion flask_restplus/templates/swagger-ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%}
Expand Down
10 changes: 10 additions & 0 deletions tests/test_apidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down