question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Try It Out!` requests fail if `servers: []`

See original GitHub issue
Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? 3.0.0
Which Swagger-UI version? 3.14.0 / g1f0dc054
How did you install Swagger-UI? git
Which browser & version? Chrome 66.0.3359.139 (Official Build) (64-bit)
Which operating system? Ubuntu 18.04

Demonstration API definition

https://gist.githubusercontent.com/dtkav/c49eeb14bcf5bd2370f74ba79cce9358/raw/21ac1f4a18813e7cde2da51596d1a91fd86233a1/petstore.yml

openapi: 3.0.0
servers: []  # this breaks swagger-ui
# ... 
# for entire spec see gist linked above

Configuration (browser query string, constructor, config.yaml)

{
        url: "https://gist.githubusercontent.com/dtkav/c49eeb14bcf5bd2370f74ba79cce9358/raw/21ac1f4a18813e7cde2da51596d1a91fd86233a1/petstore.yml",
        dom_id: '#swagger-ui',
        deepLinking: true,
        presets: [
          SwaggerUIBundle.presets.apis,
          SwaggerUIStandalonePreset
        ],
        plugins: [
          SwaggerUIBundle.plugins.DownloadUrl
        ],
        layout: "StandaloneLayout"
      }

Expected Behavior

According to: https://swagger.io/docs/specification/api-host-and-base-path/ If the server block doesn’t exist, or is empty then it shall default to ‘/’ This seems to work for a missing servers block, but not for an empty list.

Current Behavior

and empty server block results in the following console error when attempting to make any requests:

system.js:461 TypeError: Cannot read property 'url' of undefined
    at s (index.js:1)
    at a (index.js:1)
    at Object.o [as buildRequest] (index.js:1)
    at actions.js:357
    at Object.dispatch (utils.js:121)
    at dispatch (<anonymous>:1:27776)
    at bindActionCreators.js:3
    at wrap-actions.js:30
    at Object.r (system.js:173)
    at Object.executeRequest (system.js:458)
    at actions.js:397
    at Object.dispatch (utils.js:121)
    at dispatch (<anonymous>:1:27776)
    at bindActionCreators.js:3
    at spec-wrap-actions.js:9
    at Object.r (system.js:173)
    at Object.execute (system.js:458)
    at r.onClick (execute.jsx:24)
    at Object.r (ReactErrorUtils.js:24)
    at a (EventPluginUtils.js:83)
    at Object.s [as executeDispatchesInOrder] (EventPluginUtils.js:106)
    at h (EventPluginHub.js:41)
    at m (EventPluginHub.js:52)
    at Array.forEach (<anonymous>)
    at r (forEachAccumulated.js:22)
    at Object.processEventQueue (EventPluginHub.js:252)
    at r (ReactEventEmitterMixin.js:15)
    at Object.handleTopLevel [as _handleTopLevel] (ReactEventEmitterMixin.js:25)
    at o (ReactEventListener.js:70)
    at r.perform (Transaction.js:141)
    at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:60)
    at Object.o [as batchedUpdates] (ReactUpdates.js:95)
    at dispatchEvent (ReactEventListener.js:145)

Possible Solution

Looks like a default is set wrong, but I haven’t yet been able to track it down in the code.

Context

I converted an example petstore spec from swagger 2.0 to OAS3 using https://mermade.org.uk/openapi-converter and it output the following servers block.

servers: []

I then tried to use this with swagger UI and was unable to make any “Try It Out!” requests.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dtkavcommented, May 17, 2018

ah ok TIL, thanks @shockey !

0reactions
lock[bot]commented, Jul 2, 2019

Locking due to inactivity.

This is done to avoid resurrecting old issues and bumping long threads with new, possibly unrelated content.

If you think you’re experiencing something similar to what you’ve found here: please open a new issue, follow the template, and reference this issue in your report.

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Try It Out GET request: OPTIONS returns 200 but Server ...
Try It Out GET request: OPTIONS returns 200 but Server Response is Undocumented/TypeError: Failed to fetch #1878.
Read more >
generated curl request works, but try-it-out feature gives no ...
In my Swagger-UI project, when I click Try-it-out, I get an error that says "No response from server." It has response code 0....
Read more >
How To Resolve the “Requests to the Server Have ... - YouTube
This is evident when you consider what a browser can integrate into ... Server Have Been Blocked by an Extension” Error 3:48 What...
Read more >
How do you know what's gone wrong when your API request ...
When an API request doesn't work, hopefully the client receives a sensible HTTP error status, like 409 or 500, which is a good...
Read more >
HTTP conditional requests - MDN Web Docs - Mozilla
All conditional headers try to check if the resource stored on the server ... If it fails, the range request fails, and instead...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found