djangodjango-rest-frameworkcore-api

Django Rest Framework include_docs_urls adding _0 to action


We have urls in our Django (Rest Framework) applications like:

r'^endpoint/(?P<item>[a-z_-]+)/$'
r'^endpoint/(?P<item>[a-z_-]+)/(?P<version>[0-9]+(\.[0-9])?)/$'

Both have POST methods available.

We've been using Swagger for a while to document our API but wanted to look at the coreapi documentation included in Django Rest Framework.

Going through our documentation based on the above structure the coreapi action results in:

# Initialize a client & load the schema document
client = coreapi.Client()
schema = client.get("http://localhost:8081/docs/")

# Interact with the first url
action = ["app", "endpoint &gt; create"]

# Interact with the second url
action = ["app", "endpoint &gt; create_0"]

I can understand where create_0 is coming from, but ideally it would add the keyword name as a suffix instead, e.g. create_version.

Is this possible?


Solution

  • Having two keywords right after each other seems to be the problem.

    r'^endpoint/(?P<item>[a-z_-]+)/$'
    r'^endpoint/(?P<item>[a-z_-]+)/(?P<version>[0-9]+(\.[0-9])?)/$'
    

    Should be replaced with:

    r'^endpoint/(?P<item>[a-z_-]+)/$'
    r'^endpoint/(?P<item>[a-z_-]+)/version/(?P<version>[0-9]+(\.[0-9])?)/$'
    

    That will give you:

    action = ["endpoint", "item > version > create"]
    

    Which looks much cleaner.