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

Support openAPI relative path #24

Closed
sbilello opened this issue Nov 22, 2022 · 10 comments
Closed

Support openAPI relative path #24

sbilello opened this issue Nov 22, 2022 · 10 comments

Comments

@sbilello
Copy link

sbilello commented Nov 22, 2022

Hello!
Thanks for creating this project!

I was curious if we are able to extend the openApi param to support a relative file system url and not only a url.

Example:

 openApi: `./swagger.json`

Does this tool supports both openAPI 3 and swagger 2.0 json specifications?

@wll8
Copy link
Owner

wll8 commented Nov 22, 2022

In theory, open api 3 and 2 can be supported, and relative paths are also supported (depending on your own deployment location).

However, I will give a definitive answer after testing later.

@wll8
Copy link
Owner

wll8 commented Nov 22, 2022

Compatible with yaml/json/3.0/2.0

Relative paths are supported, but it looks like you need to deal with basePath in openApi (this part may not be what redoc-try should do swagger-api/swagger-ui#5981)

@sbilello
Copy link
Author

Thanks for checking!

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>redoc try demo</title>
</head>
<body>
  <div id="redoc-container"></div>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/bundles/redoc.standalone.min.js"> </script>
  <script src="./dist/try.js"></script>
  <script>
    // initTry(`https://petstore.swagger.io/v2/swagger.json`)
    initTry({
      openApi: `./test/swagger.json`,
      redocOptions: {scrollYOffset: 50},
    })
  </script>
</body>
</html>

It works as parameter appended to the url. The above does not work. I am not super familiar with js.
Is there a way to remove the URL param exposure?

@wll8
Copy link
Owner

wll8 commented Nov 23, 2022

@sbilello I created a project using your code above, please try if it helps.

👉 https://stackblitz.com/edit/redoc-try-issues-24?file=index.html

image

@sbilello
Copy link
Author

sbilello commented Nov 23, 2022 via email

@wll8
Copy link
Owner

wll8 commented Nov 23, 2022

It uses http-server instead of opening files directly via open.

When opening a file through the open command, the file:// protocol is used, which does not allow ajax to read the file. So it is recommended to use the http:// method.

see: https://stackoverflow.com/questions/39007243/cannot-open-local-file-chrome-not-allowed-to-load-local-resource

@sbilello
Copy link
Author

sbilello commented Nov 23, 2022 via email

@wll8
Copy link
Owner

wll8 commented Nov 23, 2022

Maybe it works out of the box for simple http protocol on linux/mac

# python<=2.3
python -c "import SimpleHTTPServer as s; s.test();" 8000
# python>=2.4
python -m SimpleHTTPServer 8000
# python 3.x
python -m http.server 8000

@sbilello
Copy link
Author

sbilello commented Nov 23, 2022 via email

@wll8
Copy link
Owner

wll8 commented Nov 23, 2022

https://wll8.github.io/redoc-try/index.html?openApi=./test/openapi.3.yaml

The parameters on the url are just for me to switch the demo parameters, in fact, you don't need it, there is no problem of overwriting.

It is recommended to refer to the code in this place:

https://stackblitz.com/edit/redoc-try-issues-24?file=index.html

@wll8 wll8 closed this as completed Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants