-
Notifications
You must be signed in to change notification settings - Fork 761
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
Support file:// urls #1044
Comments
@webron, Is there a workaround for being able to use I was looking into it, and from a naive understanding of the code & dependencies, I'd have to fork & enhance |
@matthewadams, by this:
do you mean that you already have your spec downloaded, and want to provide it directly to the library? |
Yes
…On Fri, Jun 9, 2017 at 6:49 PM shockey ***@***.***> wrote:
@matthewadams <https://github.com/matthewadams>, by this:
Is there a workaround for being able to use swagger-js with a service that
requires separate, manual download of its spec
do you mean that you already have your spec downloaded, and want to
provide it directly to the library?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1044 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAbdoEf1HAl6jLK5az2KMo7qaSUnqeJdks5sCdnxgaJpZM4NSNCK>
.
|
A simpler alternative might be to allow a resolved spec to be passed into the client. For example: const spec = require('./swagger-spec.json');
Swagger(spec).then(client => ...); It seems silly to try to make a request of any sort to read a local file. |
@boblauer I agree |
@boblauer @matthewadams you can do this (found here)
|
Oooh I'll have to give that a try!
…On Tue, Jun 27, 2017 at 3:51 PM Troy Cosentino ***@***.***> wrote:
@boblauer <https://github.com/boblauer> @matthewadams
<https://github.com/matthewadams> you can do this (found here
<swagger-api/swagger-ui#1110>
import SpecFile from '../spec.json';
Swagger({ spec: SpecFile }).then((client) => {
console.log(client);
});
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1044 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAbdoCpijlJ_rGnkg3JjmXHL-XmjLaocks5sIWtcgaJpZM4NSNCK>
.
|
@tcosentino I'm curious, why the need for the thenable call when providing the JSON spec already loaded? |
@c4milo Just the way they've set up the constructor. I assume with the spec option it isn't doing anything async, but the pattern remains the same. There may be a way to do it without, i.e. the constructor may return the client? Just haven't tried that |
@matthewadams, did @tcosentino's solution solve your use case? |
for new people landing here, this is how I did it with a Nuxt plugin: import Vue from 'vue';
import Swagger from 'swagger-client';
import APISpec from '~assets/identity.swagger.json';
const APIClient = {
install (Vue, options) {
Swagger({ spec: APISpec }).then((client) => {
Vue.prototype.$client = client;
Vue.prototype.$api = client.apis;
}, (error) => {
console.error('failed to load api spec: %o', error);
});
}
};
Vue.use(APIClient); |
I'm going to close this one out, here's why:
As for loading in a definition that you already have in memory, @c4milo is correct: you can pass your definition as a JS object under the Feel free to reply if you disagree with any of this, and I'll consider reopening. Thanks everyone! |
@tcosentino: Just getting back to this. Your comment (#1044 (comment)) worked out nicely, and motivated me to add #1292. Thanks! |
Its unfortunate the io for fetching the spec has been so tightly coupled to the constructor of the resulting client. Seems like that complicates the default path (how is this fetch going to work?), and gets in the way (purposeless async) if you have the spec already. |
@bcomnes, it's not completely purposeless, IMO. We see definitions that are multiple megabytes of JSON - certainly, having the building of a client instance for that definition on the event loop is nicer than it locking up your main thread for a while. |
I was under the impression that the async step came from the fetching of a remote spec resource. The processing of the spec is also chunked across even loop turns? (e.g. using the The use case I'm looking for here is creating a js client for an open API endpoint, similar to what the Java based code generator creates, but avoiding having to muck around with a java dependency. Perhaps there is a more direct path to that? Basically looking to create something simple that can be required/Imported without having to force async initialization by default. |
Enhance
swagger-client
to supportfile://
urls in order to allow the use of the package from Node.js server-side code.The following code throws an error:
I do see https://github.com/bitinn/node-fetch/blob/master/LIMITS.md, which appears to be the underlying problem. This issue, then, is dependent on the removal of that limitation. I've commented on node-fetch/node-fetch#75 in hopes that this will be resolved.
The text was updated successfully, but these errors were encountered: