Skip to content

Standardise openAPI discovery for django views #195

Description

@amirreza-sf80

Code of Conduct

  • I agree to follow Django's Code of Conduct

Feature Description

hi
at the moment there are handful of restAPI libraries in django ecosystem, and we'll probably see more coming up
one of the issues i see is, these libraries have to solve an already solved problem: openAPI generation

while we already have a number of openAPI generation tools, they are very specific to a certain library and don't work with others
specificaly, they don't work with plain django views (which one can use as an API endpoint)

i suggest we work on a standard way of how a view should be marked as an API view, so openAPI can pick it up and generate the documentation for it.

this is not to say django should make an openAPI generator (at least not now), but only a standard so people can work on it

Problem

if someone decides to write an API with plain django (or custom tools), they also have to write openAPI generator (plus other things)
but by now we already have multiple versions of this.

Request or proposal

proposal

Additional Details

No response

Implementation Suggestions

the simplest way i can think of is adding attributes to the view function

my_view.methods = ("GET", "POST")
my_view.returns = [{200: result_form, 404: str}]
...

which could become a decorator like

@api(methods=("GET", "POST"), returns=[{...}])
def my_view(request): ...

and tools can check if a view has these attributes or not

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions