42Crunch/vscode-openapi

Preview doesn't open (both swagger and redoc) when referencing other files while specifying type

Opened this issue · 2 comments

VSCode 1.84.2 on MAC
OpenAPI Editor v4.18.6

I've been having some issues where the preview doesn't open (both swagger and redoc). After doing some investigation I have found that the issue seems to occur when all of the following conditions are true.

  1. one of my schemas references another file
  2. the schema specifies type in addition to the reference to the other file (don't ask me why, someone else wrote it)
  3. the other file in it's turn has a reference to a third file

If 1 doesn't hold true, and I inline the schema from the other file, I get YAML syntax error for duplicate keys and the preview won't open, so I wonder if it's just invalid syntax even when I use a ref and "override" the type. However, since I only have a problem if 3 holds true, not just 1 and 2, it seems like it's supposed to be supported?

I've created a repro here.

These are some logs that I got in VSCode that I think are related:

2023-11-23 00:17:39.908 [error] Error: Unexpected exception while bundling: Error: Error resolving $ref pointer "file:///Users/seb/development/reproductions/openapi/External2.yml". 
"file:///Users/seb/development/reproductions/openapi/External2.yml" not found.
    at /Users/seb/.vscode/extensions/42crunch.vscode-openapi-4.18.6/out/bundler.js:235:23
    at Generator.throw (<anonymous>)
    at rejected (/Users/seb/.vscode/extensions/42crunch.vscode-openapi-4.18.6/out/bundler.js:29:65)
2023-11-23 00:17:39.930 [error] TypeError: Cannot read properties of undefined (reading '0')
    at t.GitService.getRootRepo (/Users/seb/.vscode/extensions/codium.codium-0.7.17/dist/extension.js:2:990217)
    at t.GitService.initialize (/Users/seb/.vscode/extensions/codium.codium-0.7.17/dist/extension.js:2:989020)
    at runNextTicks (node:internal/process/task_queues:60:5)
    at listOnTimeout (node:internal/timers:538:9)
    at processTimers (node:internal/timers:512:7)
    at m.activate (/Users/seb/.vscode/extensions/codium.codium-0.7.17/dist/extension.js:2:869601)
2023-11-23 00:18:04.052 [error] Error: Unexpected exception while bundling: Error: Error resolving $ref pointer "file:///Users/seb/development/reproductions/openapi/External2.yml". 
"file:///Users/seb/development/reproductions/openapi/External2.yml" not found.
    at /Users/seb/.vscode/extensions/42crunch.vscode-openapi-4.18.6/out/bundler.js:235:23
    at Generator.throw (<anonymous>)
    at rejected (/Users/seb/.vscode/extensions/42crunch.vscode-openapi-4.18.6/out/bundler.js:29:65)
2023-11-23 00:18:05.066 [error] Error: Unexpected exception while bundling: Error: Error resolving $ref pointer "file:///Users/seb/development/reproductions/openapi/External2.yml". 
"file:///Users/seb/development/reproductions/openapi/External2.yml" not found.
    at /Users/seb/.vscode/extensions/42crunch.vscode-openapi-4.18.6/out/bundler.js:235:23
    at Generator.throw (<anonymous>)
    at rejected (/Users/seb/.vscode/extensions/42crunch.vscode-openapi-4.18.6/out/bundler.js:29:65)
2023-11-23 00:18:29.893 [error] Error: Unexpected exception while bundling: Error: Error resolving $ref pointer "file:///Users/seb/development/reproductions/openapi/External2.yml". 
"file:///Users/seb/development/reproductions/openapi/External2.yml" not found.
    at /Users/seb/.vscode/extensions/42crunch.vscode-openapi-4.18.6/out/bundler.js:235:23
    at Generator.throw (<anonymous>)
    at rejected (/Users/seb/.vscode/extensions/42crunch.vscode-openapi-4.18.6/out/bundler.js:29:65)
    at runNextTicks (node:internal/process/task_queues:60:5)
    at listOnTimeout (node:internal/timers:538:9)
    at processTimers (node:internal/timers:512:7)

Of note is that the file url (file:///Users/seb/development/reproductions/openapi/External2.yml) is actually incorrect here and that file does not exist. It looks like it's resolved the relative path relative to the entrypoint openapi file, not to the other referenced file that references this third file. Keep in mind though that everything is working correctly if 2 above is not true.

If I change the reference in the "other" file to be relative to the entrypoint openapi file, I still get the same error, even though the file url mentioned is now correct and the file does exist.

2023-11-23 00:56:52.186 [error] Error: Unexpected exception while bundling: Error: Error resolving $ref pointer "file:///Users/seb/development/reproductions/openapi/models/External2.yml". 
"file:///Users/seb/development/reproductions/openapi/models/External2.yml" not found.
    at /Users/seb/.vscode/extensions/42crunch.vscode-openapi-4.18.6/out/bundler.js:235:23
    at Generator.throw (<anonymous>)
    at rejected (/Users/seb/.vscode/extensions/42crunch.vscode-openapi-4.18.6/out/bundler.js:29:65)
2023-11-23 00:56:54.559 [error] Error: Unexpected exception while bundling: Error: Error resolving $ref pointer "file:///Users/seb/development/reproductions/openapi/models/External2.yml". 
"file:///Users/seb/development/reproductions/openapi/models/External2.yml" not found.
    at /Users/seb/.vscode/extensions/42crunch.vscode-openapi-4.18.6/out/bundler.js:235:23
    at Generator.throw (<anonymous>)
    at rejected (/Users/seb/.vscode/extensions/42crunch.vscode-openapi-4.18.6/out/bundler.js:29:65)

As final note, I do have quite a lot of extensions, don't know if it's possible another extension would be interfering?

Hi! Thanks a lot for a detailed report and especially providing the sample repo. This looks like something for us too look into, I don't think it's caused by other extension. I'll update the issue once we've looked into it in more detail.

The issue is related to the bug in our bundler which fails to resolve references in the provided repo. Additionally, the exception which was thrown during the bundling process wasn't handled properly and although preview didn't work, there was no error message shown.

I'm going to fix issue with the error reporting, but fixing the bundler issue will likely take more time.

If possible it might be a good idea to restructure schemas in your OAS, in particular getting rid of the reference to a third file.