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.37k stars 262 forks source link

Yaml schema gets downloaded instead of shown inline #1282

Open MattyCZ opened 1 month ago

MattyCZ commented 1 month ago

Describe the bug If I put SpectacularAPIView the view downloads the yaml file instead of showing it inline

To Reproduce urls.py

urlpatterns = [
...
    path("docs/api/swagger.yaml", SpectacularAPIView.as_view(), name="schema"),
...
]

open at localhost:8000/docs/api/swagger.yaml, file gets downloaded instead of shown inside browser Tested on chrome Version 128.0.6613.84 (Official Build) (64-bit) Firefox 128.0.3 (64-bit)

Expected behavior Documentation yaml file is opened in browser instead of downloaded into the system

This might be bug in the browsers, because when I use curl -I, the Content-Disposition: inline header is present in the response

tfranzel commented 1 month ago

Hi, this has come up before years ago. For some reason browsers don't like to display yaml files. Chrome for example has no issues showing json, but always downloads the yaml. The inline disposition was to coerce the browser to render the schema and in case of download give it a sensible filename.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition

Also I just noticed that the schema?format=json has stopped working somehow.

https://github.com/tfranzel/drf-spectacular/pull/607 https://github.com/tfranzel/drf-spectacular/pull/621

In general, I am not sure how to massage the response so that browsers are happy with it. Please feel free to investigate better handling and we can come up with a better solution if possible.