Possible to run Swagger-UI locally?

1,090 views
Skip to first unread message

Tom Johnson

unread,
Jun 16, 2015, 1:28:58 PM6/16/15
to swagger-sw...@googlegroups.com
Is it possible to run Swagger locally? The url value in the index.html file looks like this:


If you change it to a local path, then when you view the index.html file in a browser, Swagger says the protocol for the URL must be http.

Ron Ratovsky

unread,
Jun 16, 2015, 1:30:25 PM6/16/15
to swagger-sw...@googlegroups.com
can you explain what you mean by a local path?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

Josh Ponelat

unread,
Jun 16, 2015, 1:32:21 PM6/16/15
to swagger-sw...@googlegroups.com
I think he means 'file://'

Unfortunately, that is a built in security feature on all browsers. Swagger-Ui uses ajax to fetch files, and that can only be accomplished if you run it on a server.
However that is pretty easy, as there are plenty servers out there that can be set up in a few moments (depends on how much control you want of course :D) 

--

Ron Ratovsky

unread,
Jun 16, 2015, 1:39:01 PM6/16/15
to swagger-sw...@googlegroups.com
Ah, fair enough, you can also load the definition directly into the index.html.

Tom Johnson

unread,
Jun 16, 2015, 1:55:31 PM6/16/15
to swagger-sw...@googlegroups.com
Thanks. 

I'm trying to provide a simple demo of using Swagger for REST API endpoint documentation. I wanted to put an endpoint for this Mashape API into Swagger:


I used the Swagger online editor to create the swagger spec like this:


The swagger-ui URL is here:


Seems like it sort of works. However, when I hit the Try it out button, I want the response to actually populate into the Swagger UI. Do you know what I'd need to do to make this happen?

I'm not really sure if I can even do this with the Mashape API. 

Tom



---------------------
blog: idratherbewriting.com
twitter: tomjohnson

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/Nn5cB5DlVvw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

Ron Ratovsky

unread,
Jun 16, 2015, 2:32:02 PM6/16/15
to swagger-sw...@googlegroups.com
Hi Tom,

It looks like you're missing two things - you need to set the API to use https instead of http (using the 'schemes' property) and you need to add the X-Mashape-Key header (either as an actual header parameter or as a security definition).

Tom Johnson

unread,
Jun 16, 2015, 2:54:25 PM6/16/15
to swagger-sw...@googlegroups.com
Thanks for your help. Changing the schemes property to https makes the calls go through. However, I'm getting hung up on the security part. The response I get is:

"message": "Missing Mashape application key. Go to http://docs.mashape.com/api-keys to learn how to get your API application key."

For the security, I added this to my swagger spec file:

securityDefinitions:
  api_key:
    type: apiKey
    name: X-Mashape-Authorization
    in: header

I was trying to figure out the right format for the Security object based on the documentation here: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#securityDefinitionsObject

However, I'm a bit lost. The cURL call for the API shows the authorization submitted in the header:

curl --get --include 'https://simple-weather.p.mashape.com/aqi?lat=1.0&lng=1.0' \ -H 'X-Mashape-Key: EF3g83pKnzmshgoksF83V6JB6QyTp1cGrrdjsnczTkkYgYrp8p' \ -H 'Accept: text/plain'

How can I include this authorization in the header of my Swagger UI? I would appreciate any help, especially if you can show explicitly how to add this authorization into my swagger spec or index.html file. Thanks,

Tom

---------------------
blog: idratherbewriting.com
twitter: tomjohnson

Ron Ratovsky

unread,
Jun 16, 2015, 2:58:17 PM6/16/15
to swagger-sw...@googlegroups.com

The security definitions are not automatically rendered and used for api keys at the moment.

You can follow this guide.

In short, you’d want to add something along the lines of swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization("X-Mashape-Key", "EF3g83pKnzmshgoksF83V6JB6QyTp1cGrrdjsnczTkkYgYrp8p", "header"));.

Please keep me posted of your progress.

Tom Johnson

unread,
Jun 16, 2015, 3:31:03 PM6/16/15
to swagger-sw...@googlegroups.com
Awesome, I think it's working now. Thanks! 



---------------------
blog: idratherbewriting.com
twitter: tomjohnson

Ron Ratovsky

unread,
Jun 16, 2015, 3:31:46 PM6/16/15
to swagger-sw...@googlegroups.com
Great news, thanks for the update.
Reply all
Reply to author
Forward
0 new messages