Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger-ui keeps showing example petstore instead of provided swagger.json

Tags:

I followed instructions to set up swagger documentation for my existing node API using swagger-jsdoc. The swagger.json is being served correctly and I added a path to it in the url parameter of the SwaggerUiBundle in index.html like this:

const ui = SwaggerUIBundle({
url: "https://my.domain:5292/swagger.json",
dom_id: '#swagger-ui',
presets: [
  SwaggerUIBundle.presets.apis,
  SwaggerUIStandalonePreset
],
plugins: [
  SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout" })

However, the first thing it tries to do when opening the page in the browser is showing the default http://petstore.swagger.io/v2/swagger.json instead of my swagger.json. It actually fails to do so because I'm serving the page through https and the petstore is not https but that's a different matter...

Inputing my address to the swagger.json manually into the form on the page works as expected. It shows the API page correctly and validates it. However, I don't want to always re-enter the address there and would like to have it as a default.

like image 408
md2312 Avatar asked May 10 '17 09:05

md2312


People also ask

What is Swagger petstore?

This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger.

What generates Swagger JSON?

Swagger will automatically generate a swagger. json file for us at the endpoint localhost:8080/v2/api-docs which includes information about our APIs.

What is the difference between Swagger and Swagger UI?

Swagger Editor: Swagger Editor lets you edit OpenAPI specifications in YAML inside your browser and to preview documentations in real time. Swagger UI: Swagger UI is a collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from an OAS-compliant API.

Does Swagger use JSON?

Swagger definitions can be written in JSON or YAML. In this guide, we only use YAML examples, but JSON works equally well.


1 Answers

Swagger UI 3.0.9 had a bug where it ignored the url parameter and always opened Petstore.

It was fixed in 3.0.10.

like image 71
Helen Avatar answered Sep 24 '22 10:09

Helen