-
Notifications
You must be signed in to change notification settings - Fork 303
Description
{format}
currently creates a duplicate end-point with {format}
literally in the OpenAPI endpoint path, add the duplicate includes a path parameter of type 'string'.
e.g.
/oscarapi/baskets/{basket_pk}/lines/{id}/
/oscarapi/baskets/{basket_pk}/lines/{id}{format}
They should not be considered distinct endpoints - effectively /
is a added by Django's APPEND_SLASH = True
setting, and the duplication in the paths is caused by that and the fact that foo{format}
must be able to have non-/
values because it supports foo.json
, not foo/.json
.
The trailing /
is just "no url format" for the same end-point, deferring to content-type header.
It should be an non-mandatory enum, typically it will contain only literals ['/', '.json']
, or just ['.json']
if APPEND_SLASH = False
.
The allowable values are dynamic, depending on the view, or DEFAULT_RENDERER_CLASSES
.
{format}
also provides a URL query argument, as described at https://www.django-rest-framework.org/api-guide/format-suffixes/#query-parameter-formats . This should be included in the OpenAPI as an in:query
parameter. https://swagger.io/docs/specification/describing-parameters/#query-parameters . I have not tried url .../blah.json?format=yaml
Worth noting, DRF setting 'URL_FORMAT_OVERRIDE': None,
does not appear to prevent this {format}
behaviour (@master drf). Maybe it only inhibits the addition of the format parameter when not specified by the view. i.e. django-oscar-api explicitly has a format arg in all the view action methods. I'll dig into this aspect in the drf codebase to find out the specifics of why I dont seem to be able to turn it off. May also be some package doing monkey patching, or altering of live settings.
IMO even if the settings are set up to allow .json
, I can forsee interest in preventing it in their API docs, so that {format}
becomes a mandatory /
in the path, and the format
path arg becomes redundant. The reason is that .json
is handy/quick for devs to pick a content type for get requests explicitly in the urlbar etc, but that isnt worth the generated OpenAPI being more complicated. Some sites might consider it it is a hidden feature that isnt supported.