tfranzel / drf-spectacular-sidecar Goto Github PK
View Code? Open in Web Editor NEWServe self-contained distribution builds of Swagger UI and Redoc with Django.
License: BSD 3-Clause "New" or "Revised" License
Serve self-contained distribution builds of Swagger UI and Redoc with Django.
License: BSD 3-Clause "New" or "Revised" License
I've recently integrated drfspectcular-sidecar
into my Django project to manage internal documentation, utilizing cloud services like S3 bucket for hosting. After completing the integration, I added drf-spectcular-sidecar
to the installed apps section of my Django settings and ran the collectstatic
command. This process generated a swagger-ui-dist
folder containing several necessary files:
However, upon attempting to display Swagger UI documentation using a custom HTML file hosted on an S3 bucket, nothing appears. Here's the code snippet I've utilized:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Swagger UI Documentation</title>
<!-- Include Swagger UI CSS -->
<link rel="stylesheet" type="text/css" href="swagger-ui-dist/swagger-ui.css">
</head>
<body>
<!-- Swagger UI Container -->
<div id="swagger-ui"></div>
<!-- Include Swagger UI JavaScript -->
<script src="swagger-ui-dist/swagger-ui-bundle.js"></script>
<script src="swagger-ui-dist/swagger-ui-standalone-preset.js"></script>
</body>
</html>
I would appreciate any guidance or insights on resolving this issue and ensuring proper integration of Swagger UI with Django REST Framework Spectacular in this context. Additionally, if there are any suggestions for automating the endpoint documentation update process in standalone central location like s3 bucket, they would be highly valuable. Thank you for your assistance.
Hello, maybe something is wrong in my env or this point is missing in staticfile with drf spec sidecar:
my system has no connection to the internet, thats why I deploying my project offline with sidecar.
swagger-ui is working fine, all of the required files a loaded from local (static) path, but redoc not does not for one specific file:
the /redoc loads very long, the browser debug console shows this file causes the timeout:
https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;700&family=Roboto:wght@300;400;700&display=swap
the html head is this for /redoc:
<head>
<title>REST API</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;700&family=Roboto:wght@300;400;700&display=swap">
</head>
compared to /swagger-ui
<head>
<title>REST API</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="/static/drf_spectacular_sidecar/swagger-ui-dist/favicon-32x32.png">
<link rel="stylesheet" href="/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui.css">
</head>
I have no idea where to fix it, because I have not found a options for this.
Hello @tfranzel!
Firstly thanks very much for the hard work. The drf-spectacular
project is a godsend.
I understand this repository is only three days old, so I am not sure if it is functional yet.
I installed from pip and added the app to installed apps as instructed but see no change in Django admin.
Upon inspecting the source code it looks like there's supposed to be an additional Django app listed but as mentioned I see nothing new.
Am I missing something obvious, or is it too early to use this project?
Perhaps the README can be updated to either include explicit steps after installation or indicate that it is not ready yet (if that is the case.)
Hello,
Currently our project uses drf_spectacular and it works fine. I'm trying to change swagger to be available offline by introducing sidecar, but I don't know what I set wrong that caused this:
Refused to apply style from 'http://127.0.0.1:8000/api-static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
GET http://127.0.0.1:8000/api-static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-standalone-preset.js net::ERR_ABORTED 404 (Not Found)
GET http://127.0.0.1:8000/api-static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js net::ERR_ABORTED 404 (Not Found)
Refused to execute script from 'http://127.0.0.1:8000/api-static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-bundle.js because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
Refused to execute script from 'http://127.0.0.1:8000/api-static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui-standalone-preset.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
swagger/:132 Uncaught ReferenceError: SwaggerUIBundle is not defined
versions involved:
drf-spectacular 0.26.2
drf-spectacular-sidecar 2023.12.1
Settings in settings.py:
INSTALLED_APPS = [
......,
'drf_spectacular',
'drf_spectacular_sidecar',
]
SPECTACULAR_SETTINGS = {
......,
'SWAGGER_UI_DIST': 'SIDECAR',
'SWAGGER_UI_FAVICON_HREF': 'SIDECAR',
'REDOC_DIST': 'SIDECAR',
}
urlpatterns in urls.py:
urlpatterns = [
......,
re_path(r'^api/schema/', SpectacularAPIView.as_view(), name='schema'),
re_path(r'^api/swagger/', SpectacularSwaggerView.as_view(), name='swagger'),
re_path(r'^api/redoc/', SpectacularRedocView.as_view(), name='redoc'),
]
After python3 manage.py collectstatic
, I can see all files properly copied to 'api-static/drf_spectacular_sidecar'. However, it seems when accessing, those files are not found.
I also tried adding more settings based on tfranzel/drf-spectacular#797 (comment), but it doesn't work either.
Please let me know what should I do to solve this. Really appreciate it!
Hi,
README describes
This is a self-updating and self-publishing repository that looks for updates once a week.
However, I see that releases are once a month since 376c697.
Is it possible to revert it (for every week) or is it possible to generate a new release on request?
Context:
I noticed that the latest version (2024.3.1
) of drf-spectacular-sidecar
contains swagger-ui-dist
in version 5.11.8
. We already know that this version introduced the bug that is breaking our deployment. The bug was already fixed and will be released next week (swagger-api/swagger-ui#9645 (comment)).
It means that we would have to wait a whole month for the new version of drf-spectacular-sidecar
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.