-
Notifications
You must be signed in to change notification settings - Fork 63
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
Add support for file type #34 #90
Conversation
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
Can one of the admins verify this patch? |
3 similar comments
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
1f61fa5
to
2891952
Compare
@slnode ok to test |
Hello @zbarbuto, thank you for the pull request! The changes looks mostly good to me, however I think we need to be more careful about the new type name. TL;DR: let's use Background: see the discussion in strongloop/loopback#2554. As of strongloop/strong-remoting#370, only |
@bajtos Fair enough. Updated.
Interesting. I thought this wasn't the case as the model name gets lower-cased loopback throws an error if the application tries to define a model called 'file' or 'File': Or by 'application-defined' do you mean core to loopback? |
@@ -141,11 +141,6 @@ function convertApi(v2, apiDeclaration, definitions) { | |||
} else { | |||
_.extend(target, props); | |||
} | |||
// Files hasn't made it over yet. | |||
// | |||
if (target.type === 'File') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bajtos Also removed this bock as doesn't seem to be the case anymore after this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, makes sense. Just note that AFAIK, strong-remoting does not support file uploads (input parameters of file
type) yet - see strongloop/loopback#3266
By application-defined I mean a model defined by a 3rd-party/user application using LoopBack as the framework. E.g. https://github.com/strongloop/loopback-sandbox (it does not have any File model defined though). After I looked around in strong-remoting, I am little bit confused about the benefits of your proposed changes TBH. If strong-remoting which treats |
lib/specgen/type-registry.js
Outdated
@@ -26,6 +26,7 @@ function TypeRegistry() { | |||
}, | |||
}); | |||
this.registerLoopbackType('DateString', {type: 'string', format: 'date-time'}); | |||
this.registerLoopbackType('File', {type: 'file'}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the type name should be file
for consistency with other places where we are using file
too.
test/specgen/route-helper.test.js
Outdated
@@ -103,6 +103,20 @@ describe('route-helper', function() { | |||
}); | |||
}); | |||
|
|||
it('converts { type: File\' } to { schema: { type: \'file\' } }', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, type: file
test/specgen/route-helper.test.js
Outdated
var TestModel = loopback.createModel('TestModel', {street: String}); | ||
var entry = createAPIDoc({ | ||
accepts: [ | ||
{name: 'changes', type: 'File'}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here too
The crux of it is: I want to be able to use the api explorer in conjunction with https://github.com/strongloop/loopback-component-storage in order to test file upload endpoints. At the moment, I'm having to use third-party API tools just to test my file upload endpoints. Since swagger definitely supports file uploads I thought it would just be a case of modifying the swagger gen to actually output a file upload type in the event of an In short: the purpose of this pull request is to allow us to get a file input field in our API explorer instead of just strings as are allowed now. |
@zbarbuto first of all, sorry for the delay.
That makes sense 👍 However, I think the fix will require more changes than just here in loopback-swagger. Take a look at how the file upload method is defined in lib/storage-service.js: StorageService.prototype.upload.shared = true;
StorageService.prototype.upload.accepts = [
{arg: 'req', type: 'object', 'http': {source: 'req'}},
{arg: 'res', type: 'object', 'http': {source: 'res'}},
];
StorageService.prototype.upload.returns = {arg: 'result', type: 'object'};
StorageService.prototype.upload.http =
{verb: 'post', path: '/:container/upload'}; It is accepting a full The proper solution is to implement support for file uploads in strong-remoting and then rework loopback-component-storage to let strong-remoting handle file uploads, instead of the current implementation where loopback-component-storage is parsing multipart requests itself (see lib/storage-handler.js). With that two changes in place, and this pull request landed, you should finally be able to upload files directly from our swagger-ui powered Explorer. Thoughts? |
@bajtos you're correct in that it would take multiple changes to get it to work with storage component out of the box. However in my case I'm not using the default methods provided by storage component. I've wrapped them in a custom endpoint. So what this PR achieves is allowing arbitrary endpoints to specify a file type for swagger. Then a separate issue/PR could be made for storage to support this by default. |
Sure, makes sense. |
08376ca
to
978ebbf
Compare
I have rebased you patch on top of the latest master and squashed the commits into a single one. Landed, thank you for the contribution! |
For posterity, strongloop/loopback#3266 is keeping track of the feature allowing remote method to accept file uploads. |
Also closes strongloop/loopback-component-explorer#103
Description
Allows
File
type to be turned into a file upload field.Related issues
Checklist
guide