django-rest-swagger isn't parsing/translating Markdown docstring into HTML code

1.6k views Asked by At

So far I know django-rest-swagger supports docstring in Markdown syntax from v0.1.10. But when i try to see the documentation, it is shown as plain text instead of parsing and transaling it to HTML code.

enter image description here

I'm using:

Django==1.5
Markdown==2.3.1
djangorestframework==2.3.10
django-rest-swagger==0.1.11

SWAGGER_SETTINGS = {
    "exclude_namespaces": [], # List URL namespaces to ignore
    "api_version": '0.1',  # Specify your API's version
    "api_path": "",  # Specify the path to your API not a root level
    "enabled_methods": [  # Specify which methods to enable in Swagger UI
        'get',
        'post',
        'put',
        'patch',
        'delete'
    ],
    "api_key": '', # An API key
    "is_authenticated": True,  # Set to True to enforce user authentication,
    "is_superuser": False,  # Set to True to enforce admin only access
}

API sample code function-based-view:

@api_view(['POST'])
def dummy(request):
    '''
    Lorem ipsum `dolor` sit amet, consectetur adipiscing elit. Etiam sodales lacus at _nulla_ fringilla fringilla. 

    ### Consectetur adipiscing:

       * __dummy_var__: Nunc ut erat justo. Duis turpis augue, posuere a ornare sed,
       * another: Vestibulum suscipit congue neque sed faucibus.
       * `code`: Cras sit amet ullamcorper ipsum.
    '''
    pass

When the API is browsed directly, the description is translated/rendered properly.

enter image description here

Am I missing something?

2

There are 2 answers

0
mariodev On

I don't think you're missing anything. The Markdown is only used in DRF Browsable API views. Swagger doesn't use Markdown, instead DRF uses it to render description.

Swagger just passes description and notes as string, using ajax. Then it renders both of them as html, you can check it by including html tags in the docs string. So it's not using Markdown renderer at all.

DRF uses Markdown to display description, that's why it works in Browsable API but not in api-docs.

0
stalk On

Since version v0.2.0, markdown is avaliable in django-rest-swagger!

It is needed just to install markdown package explicitly (it will not be installed automatically):

pip install markdown