Django Rest Framework include_docs_urls 将 _0 添加到操作中
Django Rest Framework include_docs_urls adding _0 to action
我们的 Django(Rest Framework)应用程序中有 url,例如:
r'^endpoint/(?P<item>[a-z_-]+)/$'
r'^endpoint/(?P<item>[a-z_-]+)/(?P<version>[0-9]+(\.[0-9])?)/$'
两者都有 POST 方法可用。
我们一直在使用 Swagger 来记录我们的 API 但想查看 Django Rest Framework 中包含的 coreapi 文档。
根据上述结构浏览我们的文档,coreapi 操作结果为:
# 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 > create"]
# Interact with the second url
action = ["app", "endpoint > create_0"]
我能理解 create_0
的来源,但理想情况下它会添加关键字名称作为后缀,例如create_version
.
这可能吗?
两个关键字紧接在一起似乎是问题所在。
r'^endpoint/(?P<item>[a-z_-]+)/$'
r'^endpoint/(?P<item>[a-z_-]+)/(?P<version>[0-9]+(\.[0-9])?)/$'
应替换为:
r'^endpoint/(?P<item>[a-z_-]+)/$'
r'^endpoint/(?P<item>[a-z_-]+)/version/(?P<version>[0-9]+(\.[0-9])?)/$'
那会给你:
action = ["endpoint", "item > version > create"]
看起来干净多了。
我们的 Django(Rest Framework)应用程序中有 url,例如:
r'^endpoint/(?P<item>[a-z_-]+)/$'
r'^endpoint/(?P<item>[a-z_-]+)/(?P<version>[0-9]+(\.[0-9])?)/$'
两者都有 POST 方法可用。
我们一直在使用 Swagger 来记录我们的 API 但想查看 Django Rest Framework 中包含的 coreapi 文档。
根据上述结构浏览我们的文档,coreapi 操作结果为:
# 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 > create"]
# Interact with the second url
action = ["app", "endpoint > create_0"]
我能理解 create_0
的来源,但理想情况下它会添加关键字名称作为后缀,例如create_version
.
这可能吗?
两个关键字紧接在一起似乎是问题所在。
r'^endpoint/(?P<item>[a-z_-]+)/$'
r'^endpoint/(?P<item>[a-z_-]+)/(?P<version>[0-9]+(\.[0-9])?)/$'
应替换为:
r'^endpoint/(?P<item>[a-z_-]+)/$'
r'^endpoint/(?P<item>[a-z_-]+)/version/(?P<version>[0-9]+(\.[0-9])?)/$'
那会给你:
action = ["endpoint", "item > version > create"]
看起来干净多了。