We have to migrate several node.js applications from Loopback3 to Loopback4.
So the first step we want to do is a basic migration following guidelines (1 and 2), and then complete it by manually upgrade methods and logic, and completely remove lb3 application.
Unfortunately, at the end of the migration steps in the guide, when trying to start the app (node -r source-map-support/register .), we receive the following error:
...
Swagger: skipping unknown type "Document".
Cannot start the application. { S2OError: Could not resolve reference #/definitions/Document
...
The same procedure on other two lb3 project has worked fine.
@nabdelgadir , could you please help? Thanks.
Hello,
now I've noticed when I start the project in lb3 I receive the following warning:
Swagger: skipping unknown type "Document".
Swagger: skipping unknown type "file".
but the project starts fine.
I hope this can help.
Hi, thanks for reporting this issue. I assume as a standalone LB3 application, this error doesn't happen? Could you please provide a sample repo to reproduce what you're getting so it's easier to debug? See https://loopback.io/doc/en/contrib/Reporting-issues.html#loopback-4x-bugs, thanks!
Hello,
I managed in reproducing the issue.
Please have a look at https://github.com/UnclePetros/loopback-next/tree/issue-3323.
The issue is related to the Investor model.
I leave out loading other models (you may see some static refs in the code), cause this was enough to reproduce the issue.
In your Investor model, you have returns: {arg: 'personalDocuments', type: '[Document]', root: true} for Investor.remoteMethod('getUserDocuments', {...}). The type has to be either a LoopBack type (see type under https://loopback.io/doc/en/lb3/Remote-methods.html#argument-descriptions) or it can be a LoopBack 3 model. So if you make a model called Document, then #/definitions/Document will reference that model. Otherwise, you have to use one of the types from LoopBack Types. I hope this helps.
Ok. Thank you for the useful info.
I've temporarily changed this return type to Object, and it runs successfully and migration goes fine. So I've solved in this way as my scope is to rewrite this specific method.
Anyway I have to say the lb3 application runs fine, even though this type is not defined in it.
In the LoopBack 3 documentation, it does say to use types LoopBack 3 recognizes for the type but I believe it just defaults to object when it doesn't recognize it. But when it's converted in buildOpenApiSpec, through the swagger2openapi module, from OpenAPI v2 to OpenAPI v3, it enforces the type constraint.
Yes, very clear answer. Thank you again for the help.
Thanks, I'll close the issue then. 馃槃