apigee-127 / swagger-tools

A Node.js and browser module that provides tooling around Swagger.
MIT License
701 stars 373 forks source link

Swagger UI middleware might not be the latest version? #553

Open tekkusan opened 6 years ago

tekkusan commented 6 years ago

I started using swagger-tools recently and came across an issue where the Swagger UI middleware published through /docs behaved differently than the "standard" one (at http://petstore.swagger.io/). In particular, the middleware version wasn't doing the nifty UI parameter validation (shaking box, etc.) when a pattern check failed or showing the proper pattern while hovering on the input (the Validator middleware did catch this, of course).

A quick check showed that the files at the petstore site and the middleware/swagger-ui directory were different, so to test I overwrote everything other than index.html with the versions from petstore, restarted my app and now this functionality was available through the middleware.

Like I said, I'm very new to swagger-tools (and swagger in general) so this could be caused by something else I'm missing, but if not, I guess it could be nice to upgrade the Swagger UI middleware version to whatever is current?

In any case, thanks for swagger-tools, it's quite a bit of fun to try to learn and work with it :)

AaronHarris commented 6 years ago

@tekkusan My guess is that this is because swagger-tools is targeted at Swagger versions 1.2 and 2.0. The latest version of swagger-ui used by petstore.swagger.io only supports Swagger 2.0 and above, so this would break for those using Swagger 1.2.

Here is my workaround:

  1. Add the latest swagger-ui-dist (which contains all the assets bundled up) to your package.json

    npm i -S swagger-ui-dist
  2. Add the following option swaggerUiDir when you initialize your SwaggerUi middleware:

    middleware.swaggerUi({ swaggerUiDir: path.join(__dirname, 'node_modules', 'swagger-ui-dist') })

Voila! 🎉There is no step 3! You now have the latest and greatest Swagger-UI for your various purposes.

taicho commented 6 years ago

@AaronHarris I love this workaround and I attempted it but I can't seem to get swagger-ui-dist to load my swagger doc as the default rather than the pet store. To clear the line above is the only thing I changed... have you had any luck with this?

shishirsharma commented 6 years ago

@taicho This did not work for me too. It looks like index.html are different. swagger-tools and swagger-ui-dist are not compatible.

marc101101 commented 6 years ago

@AaronHarris Thanks for advice. Problem is that swagger now is rendering not my swagger file, but the default petstore file. image

shishirsharma commented 6 years ago

I was not straight fwd. This is basically what I ended up doing. Ask me if you need further explanation https://gist.github.com/shishirsharma/be5f086aa4e7ff5d8b0ace64d9a4429a