Distinguish between "file" and "File" result types#370
Conversation
|
Related (more or less duplicate of): strongloop/loopback#2554 |
|
@fabien thank you for the pull request. I am ok to land this patch as short-term fix. For longer term: I think the situation where |
|
@bajtos thanks for the quick reply and aim to land it ASAP! With Will look into the discussion some more. |
|
@fabien there are few more places where we are dealing with strong-remoting/lib/shared-method.js Line 417 in 1efefa6 strong-remoting/lib/shared-method.js Line 567 in 1efefa6 strong-remoting/lib/shared-method.js Line 578 in 1efefa6 |
lib/http-context.js
Outdated
| // TODO(bajtos) call SharedMethod's convertToBasicRemotingType here? | ||
| this.resultType = typeof returnDesc.type === 'string' ? | ||
| returnDesc.type.toLowerCase() : returnDesc.type; | ||
| this.isFile = returnDesc.type === 'file'; |
There was a problem hiding this comment.
Since this is the context, the nameisFile is misleading in my opinion. How about isReturningFile?
|
@bajtos as you noted here: https://github.com/strongloop/strong-remoting/blob/2.x/lib/http-context.js#L415 Why aren't we using |
|
@bajtos I have gone ahead and used
And it would still work as expected. This means it's backwards compatible, because |
lib/shared-method.js
Outdated
| return type; | ||
| return normalizedType; | ||
| case 'file': | ||
| return type === 'File' ? normalizedType : ('res:' + normalizedType); |
There was a problem hiding this comment.
IMO we need to use a different condition here: only file should be treated as a built-in file type, everything else is a custom model (FILE, FilE`, etc.).
|
@fabien I have a different opinion here. I would rather not add a new set of type strings like As I commented in strongloop/loopback#2554 (comment), I think we should simply make Anyhow, I went ahead and simplified/cleaned up your patch in 7691ff7 to a state that looks good to myself. Could you please take a look at the resulting change? (I pushed the commit to your feature branch thanks to a recently added GitHub feature described in https://github.com/blog/2247-improving-collaboration-with-forks). If you are ok with what we have here now, then either me or you can squash the commits into a single one, provide a descriptive commit message per our contributor docs, and this pull request can be landed. |
|
@bajtos thanks for the cleaned-up patch - I'm totally fine with your implementation! If you don't mind, please go ahead and squash & pull to get it landed 👍 |
|
Only concern would be the 3.0 release upgrade path for models named |
Yes, I do realise this means users will have to rework their apps a bit when upgrading from 2.x to 3.0. As you said, this is unavoidable :( |
Fix regression introduced by a85068e where we started to treat "File" models as the new built-in type "file". In this commit, the implementation is fixed to recognize only the following form as the built-in file: { type: 'file' } All other spellings, most notably "File", are treated as custom types (models) now.
7691ff7 to
39b1956
Compare
|
Landed and released in |
|
@bajtos thanks for landing it so quickly! |
If you have a Loopback model called
Fileyou'll receive following error when it is set as a return type:Error: Cannot create a file response from objectIn other words, because
fileis now a reserved keyword with a very specific response handling logic, andFileis lowercased during normalization intoresultType, the error above would prevent any Loopback being namedFile. This introduced a breaking change for my apps.This is loosely related to #318 but in the above case, it's actually not desirable to return a file (buffer/stream) response. Perhaps a more specific keyword than simply
filewould have been better in hindsight.See also: a85068e#commitcomment-19410422
@bajtos @richardpringle