use this client with a swagger spec on local machine?
I want to use the client as following in my code:
var SwaggerClient = require('swagger-client');
var client = new SwaggerClient({
url: '../swagger/sampleSwaggerAPI.yaml',
success: function() {
...
}
});
Is that doable or does this work only with hosted swagger specs only?
@fehguy ^ thoughts please.
aah, I went thru the code and it seems, it's fetching swagger.json/yaml file by HTTP GET call to a URL. So, this could be a feature request or is there anyway to achieve it?
@fehguy: Hi Tony, I would really appreciate if could you please share your views on the above (new to Swagger world). Thank you much!
hi @gunjpan, can you load the contents of your ../swagger/sampleSwaggerApi.yaml as an object? If so, you can easily do this:
// you load the `spec` as an object
var spec = { swagger: '2.0', ....};
new SwaggerClient({
url: 'STILL_NEEDED!',
spec: spec,
...
}
Then the object can be loaded however you like, and the swagger client will process it. Note! The url field is still needed. Why might you ask? Because there may be references to other swagger constructs inside your object, and the client will need that for resolving them.
@fehguy : thank you for your reply. Yeah, I figured it out yesterday that I can pass the Swagger specification object to options.spec and got it working by parsing swagger spec file.
Re:
The url field is still needed.
So, in a case, let's assume, I only have a swagger spec file (i.e. spec obj) and url is not defined, how can this be dealt with? I mean, should the url be set to SwaggerObject.host?!
FYI, I stored petStore.json spec file on local, passed it to the spec and was able to make calls successfully!
Hi GunjPan, I am also trying to do the same.Can you please share how you had did the same.I have my product.yaml on my code and want to validate model against the yaml file.
@waytoharish : here is where I'm using SwaggerClient : https://github.com/strongloop/loopback-connector-swagger/blob/a656eedd5490869152ed3e62a708bc4de13bf00d/lib/swagger-connector.js#L107-L119
and here is the function where I'm parsing a local file: https://github.com/strongloop/loopback-connector-swagger/blob/a656eedd5490869152ed3e62a708bc4de13bf00d/lib/spec-resolver.js#L14
Hope that helps