tfranzel / drf-spectacular

Sane and flexible OpenAPI 3 schema generation for Django REST framework.
https://drf-spectacular.readthedocs.io
BSD 3-Clause "New" or "Revised" License
2.38k stars 264 forks source link

Websocket/AsyncAPI Support #667

Open johnthagen opened 2 years ago

johnthagen commented 2 years ago

drf-spectacular is excellent at generating OpenAPI schemas for REST APIs. Having something similar for use with websocket portions of DRF applications (via Django Channels) would be a big win for backends that also support web sockets.

AsyncAPI is the OpenAPI-equivalent solution for web sockets.

djangochannelsrestframework (DCRF) is a DRF-like interface for building APIs over websockets using Django Channels. It uses a very similar approach to DRF, so perhaps some of drf-spectactular's infrastructure could be reused.

Cross reference to feature request on DCRF repo:

johnthagen commented 2 years ago

The canonical issue about OpenAPI itself and websockets:

johnthagen commented 2 years ago

AsyncAPI can host a static Swagger UI-like browseable frontend:

tfranzel commented 2 years ago

As a channels user myself, this has been cumbersome for me too.I was not aware of DCRF, so thanks for that.

so perhaps some of drf-spectactular's infrastructure could be reused.

probably, however I presume that DCRF/AsyncAPI will break quite a few assumptions we made concerning the OpenAPI structure itself.

Not sure how much effort this is. I certainly find this interesting but lack the time to further look into it at the moment.

ford-carta commented 1 year ago

As a workaround, is there any way to add components to the schema manually without using a view?

tfranzel commented 1 year ago

@ford-carta not entirely sure what you intend to do, given that AsyncAPI is structured differently, but you are always free to write postprocessing hooks to mutate the schema at the end of parsing.

https://drf-spectacular.readthedocs.io/en/latest/customization.html#step-6-postprocessing-hooks