loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.94k stars 1.06k forks source link

lb4 openapi generated routes fail to work without servers field #9363

Open aaqilniz opened 1 year ago

aaqilniz commented 1 year ago

Describe the bug

While accessing the routes created with lb4 openapi, the app throws the following error:

Request GET /v3.1/all?fields=name failed with status code 500. TypeError: Only absolute URLs are supported.

This happens because the specs don't have a servers field or don't contain absolute URLs.

The docs suggest to download the specification locally and then generating the routes with lb4 openapi.

The loopback should work without needing to download the specs and shouldn't need a user to download the specification.

Is it possible to make the loopback app work even if the servers field is not provided or is not an absolute path? Can we achieve this by adding a servers field in the framework before processing the request?

Logs

Request GET /v3.1/all?fields=name failed with status code 500. TypeError: Only absolute URLs are supported
    at getNodeRequestOptions (/media/<path>/testing-cache-package/node_modules/node-fetch/lib/index.js:1327:9)
    at /media/<path>/testing-cache-package/node_modules/node-fetch/lib/index.js:1454:19
    at new Promise (<anonymous>)
    at fetch (/media/<path>/testing-cache-package/node_modules/node-fetch/lib/index.js:1451:9)
    at Function.http (/media/<path>/testing-cache-package/node_modules/swagger-client/lib/http/index.js:82:45)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Additional information

No response

Reproduction

https://github.com/aaqilniz/testing-cache-package/tree/issue-absoulte-url

aaqilniz commented 1 year ago

Hi @samarpanB. Sorry for tagging you here too. But can you provide you suggestions on the issue?

aaqilniz commented 1 year ago

I think I am misunderstanding the situation. This issue is being generated from node-fetch. That too I think is not an issue. It requires to have absolute URLs.