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

I'm having trouble implementing swagger-ui in remote server. Throwing can't read file error. #4808

Closed
rbipin opened this Issue Aug 10, 2018 · 6 comments

Comments

Projects
None yet
2 participants
@rbipin
Copy link

rbipin commented Aug 10, 2018

Q&A (please complete the following information)

  • OS: Windows
  • Browser: Chrome, Safari, IE
  • Version: [e.g. 22]
  • Method of installation: dist
  • Swagger-UI version:3.0.21
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Swagger/OpenAPI definition:

# your YAML here

Swagger-UI configuration options:

window.onload = function() {

  // Build a system
    const ui = SwaggerUIBundle({
        urls: [
            {
                url: "../OASDoc/v1_apidoc.json",
                name:"Version 1.0.0"
            }
              ],
    dom_id: '#swagger-ui',
    deepLinking: true,
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout"
  })

  window.ui = ui
}
?yourQueryStringConfig

Screenshots

https://i.stack.imgur.com/5hYMz.png

How can we help?

The swagger-ui is throwing can't read the file error from the ui. But it is working from local IIS.
The details of the issue along with the sample code is also given below in my stackoverflow questions
https://stackoverflow.com/questions/51778578/swagger-ui-is-unable-to-load-the-json-specification-file-in-serve

@rbipin rbipin changed the title I'm having trouble implementing swagger-ui in remote server. I'm having trouble implementing swagger-ui in remote server. The swagger-ui is throwing can't read the file error from the ui. But it is working from local IIS. Aug 10, 2018

@rbipin rbipin changed the title I'm having trouble implementing swagger-ui in remote server. The swagger-ui is throwing can't read the file error from the ui. But it is working from local IIS. I'm having trouble implementing swagger-ui in remote server. Throwing can't read file error. Aug 10, 2018

@shockey

This comment has been minimized.

Copy link
Member

shockey commented Aug 15, 2018

Hey @rbipin, can you give me the URL in your address bar where you're accessing Swagger UI?

(I'm not going to access it, I just want to create a URL for you so you can test something)

@rbipin

This comment has been minimized.

Copy link
Author

rbipin commented Aug 17, 2018

@shockey I can give the format of the URL, but I cannot give the actual URL as it is restricted within the company and it is a security violation to give the URL publicly.
The format of the swagger ui is http://xxxx.xxxx.com/retailproject/swaggerui/index.html

@shockey

This comment has been minimized.

Copy link
Member

shockey commented Aug 17, 2018

no worries @rbipin, I understand.

Can you see the Swagger document if you go to http://xxxx.xxxx.com/retailproject/OASDoc/v1_apidoc.json? That's where Swagger UI is looking for your document, It's possible that your server is configured incorrectly.

If that doesn't illuminate the problem, try opening the Network tab of your browser's dev tools, and take a look at the request that Swagger UI is making to fetch v1_apidoc.json.

@rbipin

This comment has been minimized.

Copy link
Author

rbipin commented Aug 20, 2018

@shockey : yes, I tried to access the json file (http://xxxx.xxxx.com/retailproject/OASDoc/v1_apidoc.json)
But i'm not able to access the file

@shockey

This comment has been minimized.

Copy link
Member

shockey commented Aug 20, 2018

@rbipin, that would be a problem with your server then - if your server isn't serving up your Swagger document at the right URL (which, based on the config and URL you shared, is the URL I mentioned above), Swagger UI won't be able to do anything 😄

@rbipin

This comment has been minimized.

Copy link
Author

rbipin commented Aug 22, 2018

@shockey thank you for helping me! Your directions were very helpful. I figured it out now and I have fixed it. The issue was the server was not serving static JSON file by default. I added the mime type mapping to me web.config file and it worked.

<system.webServer> <staticContent> <mimeMap fileExtension=".json" mimeType="application/json"/> </staticContent> </system.webServer>

@rbipin rbipin closed this Aug 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.