Giter Site home page Giter Site logo

tfranzel / drf-spectacular-sidecar Goto Github PK

View Code? Open in Web Editor NEW
26.0 2.0 3.0 28.81 MB

Serve self-contained distribution builds of Swagger UI and Redoc with Django.

License: BSD 3-Clause "New" or "Revised" License

Python 76.09% HTML 23.91%
django swagger-ui redoc openapi3 drf

drf-spectacular-sidecar's Introduction

drf-spectacular-sidecar

pypi-version pypi-dl

Serve self-contained distribution builds of Swagger UI and Redoc with Django either via runserver or collectstatic.

This Django app is an optional addition to drf-spectacular, but does not depend on it. It may also be used independently.

This is a self-updating and self-publishing repository that looks for updates on the 1st of every month. The distribution files are sourced from npm via jsdelivr, validated, packaged and uploaded to PyPI.

Installation

$ pip install drf-spectacular-sidecar

The package needs to be registered to allow Django to discover the static files.

INSTALLED_APPS = [
    # ALL YOUR APPS
    'drf_spectacular_sidecar',
]

Requirements

Django >= 2.2

Licenses

Provided by T. Franzel. Licensed under 3-Clause BSD.

This package includes distribution builds of

drf-spectacular-sidecar's People

Contributors

johnthagen avatar ngnpope avatar tfranzel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

drf-spectacular-sidecar's Issues

Swagger page blank with all files accessing showing 404

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!

Redoc - loading googefont from web instead from local path

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&amp;family=Roboto:wght@300;400;700&amp;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.

Subject: Issue with Displaying Swagger UI Documentation After Integrating Django REST Framework Spectacular SideCar

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:

  • favicon-32x32.png
  • oauth2-redirect.html
  • swagger-ui-bundle.js
  • swagger-ui-bundle.js.LICENSE.txt
  • swagger-ui-bundle.js.map
  • swagger-ui-standalone-preset.js
  • swagger-ui-standalone-preset.js.map
  • swagger-ui.css
  • swagger-ui.css.map

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.

Post-installation steps / expectations are not clearly defined

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.)

Earlier release

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.