Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Is it possible to load the Swagger UI offline? #261

Open
Joseda8 opened this issue Sep 21, 2022 · 6 comments
Open

[Question] Is it possible to load the Swagger UI offline? #261

Joseda8 opened this issue Sep 21, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@Joseda8
Copy link

Joseda8 commented Sep 21, 2022

The service I'm making runs on the localhost with not necessarily access to Internet. When I open the Swagger endpoint in the browser I can see the next messages in the console:

Loading failed for the <script> with source “https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js”. swagger:36:1
Loading failed for the <script> with source “https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-standalone-preset.js”. swagger:37:1

So I want to know... How to load the Swagger interface offline?

@kemingy kemingy added the enhancement New feature or request label Sep 22, 2022
@kemingy
Copy link
Member

kemingy commented Sep 22, 2022

Thanks for asking. I think it's possible if we package the related frontend source code into the Python package.

Does that mean you can access internal PyPI but cannot access other websites?

@jaykv
Copy link
Contributor

jaykv commented Oct 17, 2022

You can pair spectree with https://github.com/sveint/flask-swagger-ui for now. Not a perfect solution, but an easy workaround.

Here's a quick example: https://gist.github.com/jaykv/cd9afb91fa5a2fafc206345b7dd4b984

@alexted
Copy link

alexted commented Nov 7, 2022

We also use SpecTree in our closed perimeter where there is no internet access!
We take all the libraries for our apps from JFrog Artifactory or Nexus Repository (depending on the project/team), which have internet access, or rather only to global PyPi.

@cardin
Copy link

cardin commented Nov 25, 2022

A very hackish way is to overwrite spectree/page.py before SpecTree is instantiated.

from spectree.page import DEFAULT_PAGE_TEMPLATES

app = Flask(...)

def _rewrite_cdn():
   DEFAULT_PAGE_TEMPLATES["redoc"] = DEFAULT_PAGE_TEMPLATES["redoc"].replace("https://cdn.jsdelivr.net/npm/redoc@next/bundles/", "localhost/assets")

_rewrite_cdn()
spec = SpecTree("flask")
spec.register(app)

@alexted
Copy link

alexted commented Jan 27, 2024

Is there any news on this issue?

@kemingy
Copy link
Member

kemingy commented Jan 28, 2024

Is there any news on this issue?

Similar to @cardin's comment. You can pack all the swagger related HTML/CSS/JS into one string.

Assume you already done it, you can use the code below:

from spectree import SpecTree

spec = SpecTree(page_templates={"swagger": YOUR_OFFLINE_SWAGGER_HTML_STRING})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants