-
Notifications
You must be signed in to change notification settings - Fork 760
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
Can swagger-client support local files #1410
Comments
Swagger client uses fetch (or cross-fetch/polyfill) as the default client to load doc from url; it does not support file url (data url neither). However, you can use a temporary server in your scenario: https://gist.github.com/bestmike007/a63ea5b21a24fdd34508164a85dc1e4b |
Quoting myself from #1044:
As mentioned, the best approach is to pull your local file in manually, Closing! |
@shockey -- you said:
To me, this is a different suggestion than what @bestmike007 suggestion (which is fine), and I think you mean basically load the Swagger locally as an object, and then pass that to the constructor: //testing locally, so I've got the Swagger spec on my machine
const Swagger = require('swagger-client');
const fs = require('fs');
const yaml = require('js-yaml');
var url = path.join(__dirname, "./local_path/api.yaml");
var spec = yaml.safeLoad(fs.readFileSync(url), 'utf8');
Swagger({ spec: spec })
.then(function(client){
console.log("Got client!");
})
.catch(function(ex){
console.log("Error!");
console.log(ex): //We get the exception "TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received type undefined"
}) I'm certain the |
@mm-gmbd, I worded it poorly! you'd actually want to do it like I'm going to edit your comment so Googlers get the right snippet, but for any historians out there, the line was originally |
@shockey - thanks for the clarification! Also, thanks for your work on this particular module, it's very helpful! I'd love a little more documentation / examples here and there, but this beggar won't try and be a chooser 😄 (best case scenario - maybe I'll actually get some time to contribute!) |
Can swagger-client import API Docs via a file instead of an http url.
Something like:
We want to use swagger-client to exercise our rest apis where the rest apis are sitting in the repo next to the code that uses swagger-client. In particular we have some integration test cases that we use to test our rest apis.
The text was updated successfully, but these errors were encountered: