-
Notifications
You must be signed in to change notification settings - Fork 9k
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
how to load local .json file? #1110
Comments
The easiest way would probably be to embed the json inside your index.html. Check out the |
@hongxingli, You can use Relative path even i tried and it works ! Example: |
Closing for now. Reopen if needed. |
@hongxingli: Could you please provide your snippet and how you defined the path? Thanks, |
Thanks Ruki, We don't need this feature any more, at that time, I was thinking to have swagger UI pointed to a local swagger.json file. |
@rukiliii Did you ever figure this out? I'm trying to use a relative path and it doesn't seem to work. swagger-ui.js looks like it's checking the url string for "http" and mine won't have that because the path is "json/swagger.json". Nothing I've tried has made swagger-ui happy. |
On the same topic but for node.js, this works for me: var swagger = require("swagger-client"); var client = new swagger({ As someone pointed to above, don't provide a URL, it is ignored when 'spec' is provided. |
@bandtank, I'm with you. @rukiliii , a solution to this is still needed - please reopen as none of the suggestions here work (or explain in great enough detail). An easier solution that didn't have to be googled would be nice. I've added
Not sure why it's adding "index.html" like it's part of the path, but I'd presume that's at least part of the problem. EDIT: Here was my interim solution:
|
It is not possible to load Anyway, providing a swagger-ui where users can directly upload their JSon file for preview would be dangerous (or at least complicated) in terms of security. As mentioned above, embedding the json directly in the index.html file is probably the most simple workaround. |
Thanks @vincent-zurczak , that makes sense, please help close this issue. |
@ramsunvtech, Do you remember for which version this is working for you. It doesn't seem to work for me for the version 2.1.4 @vincent-zurczak, I'm trying to understand why it will be a security issue to allow uploading json files. Could you elaborate a little? I feel it is a good use-case to take care of the file:/// protocol as well. |
Uploading JSon files means having a server configuration. Which is not the intent of Swagger UI, which is basically only a client application (at least, from what I understood). But maybe what we want is not real uploading.
|
Hi, I am new to web programming. Can someone help me what I am doing wrong? I just cloned swagger UI source from https://github.com/swagger-api/swagger-ui and inside "dist", I put my local swagger.json file which I created using swagger.io editor. I added below three line of code separately and opened index.html in the browser (Chrome/Edge/Firefox) and none of them seems to be working.
I don't have npm or anything fancy installed. I am working on a Python flask back end and ultimately I want to hook this onto my server. I also tried using connexion with my flask backend but I am not able to use flask-restful with connexion (issue in both python 2 and 3) and I can't find solution for that. |
Hi Nilay, I don't know how to integrate swagger with flask, but regarding your Add your swagger.json contents directly to a variable var spec = (like var spec = Then add the spec variable to the SwaggerUi constructor (1 line change) ... Then, open your index.html in a browser. On Thu, Apr 28, 2016 at 6:59 AM, Nilay Chheda notifications@github.com
|
Thanks @ndsurendra after manually adding json content it is working fine. |
@ndsurendra Hey thanks for the solution. What if I have more than 1 json file. Do I have to manually copy/paste the content into a new variable? If so, how do I make it so that in the index.html page, there are 2 options ( option 1, option2) and based on the click, I load the swagger-ui. I tried putting the var spec for my first json file, and then var spec2 ( my 2nd json file) like this: url: url, how do I call them sepertely based on a click |
@AkashMalhotra you can't load multiple jsons into a single SwaggerUi instance. Take a look at https://gist.github.com/webron/7c41db7f777471fcbc10. |
@webron WHere do I define the url under uiswagger2? Do I just do url:path/example2.json? |
The parameter passed to it has the same value, but as long as you set |
I'm trying to basically add a button on the side that would link to the 1st json file, another button to another json file etc. What href do i add or how do I redirect a click so that it loads the different urls. https://gist.github.com/anonymous/3f37edf7ea2c2c1304473a7ac10a2b82 |
Is there any other way to load the local json file other than copy pasting the entire json in the spec? |
@ayushidalmia - Right now there's no very straightforward way to accomplish this, but this Stackoverflow answer will make it easier than the copy paste. |
It could've been solved with a simple file selector widget. I had this problem since ~2013 and totally didn't expect this issue not to be fixed. |
@polkovnikov-ph - agreed, it feels criminal that it's not that simple! |
Hi Uncaught Error: Module name "swagger-client" has not been loaded yet for context: _. Use require([]) var swagger = require('swagger-client'); //require is not working in angular JS project. var myApp = angular.module('myApp', ['swagger-client']) //then trying to get swagger-client |
FYI, this may be relevant: swagger-api/swagger-js#1292 |
|
Locking, as this is very old and resolved. Please open a new issue if you have something to add! |
I can load it through URL, but when I try to change the index.html to local json, it doesn't work, any idea how I can debug further?
BTW, I use swagger-maven-plugin to generate the json, so there are multiple json files: service.json, users.json....
The text was updated successfully, but these errors were encountered: