Skip to content
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

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

Open
sebastian-fredriksson-bernholtz opened this issue Nov 22, 2023 · 2 comments

Comments

@sebastian-fredriksson-bernholtz

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?

@ak1394
Copy link
Collaborator

ak1394 commented Nov 22, 2023

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.

@ak1394
Copy link
Collaborator

ak1394 commented Nov 28, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants