Skip to content

Not recognizing API files #125

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

Closed
msennett9 opened this issue Apr 12, 2021 · 24 comments
Closed

Not recognizing API files #125

msennett9 opened this issue Apr 12, 2021 · 24 comments

Comments

@msennett9
Copy link

I had been using the OpenAPI editor occasionally, but now when I click on the OpenAPI icon to work with an API, it simply displays the "No OpenAPI file selected" message, even though I have an API file open. Then, when I click on the "New OpenAPI file" button, nothing happens. I have updated to the latest 4.4.1 version. I have tried disabling other extensions in case there was a conflict. Is there any way to debug this? No errors are displayed in the debug console or output window. Are there any known conflicts between the OpenAPI editor and other extensions?

@ak1394
Copy link
Collaborator

ak1394 commented Apr 12, 2021

Hi @msennett9 thanks for reporting the issue, let's try to figure why it doesn't work for you.

When you say that nothing happens when you click "New OpenAPI file" button, do you mean that it does not recognize newly created document as OpenAPI file and "No OpenAPI file selected" does not goes away? Or do you mean that nothing happens at all? When you click that button it should at least create a new document with some minimal OpenAPI content in it.

What happens if you try to invoke "OpenAPI: Create new OpenAPI v3.0 file (YAML)" command through a command pallette (CMD-Shift-P)?

What happens if you try to create JSON OpenAPI file with the comand "OpenAPI: Create new OpenAPI v3.0 file"?

@msennett9
Copy link
Author

When I try to invoke the create new OpenAPI file from the palette, I am seeing an error:

Command 'OpenAPI: Create new OpenAPI v3.0 file' resulted in an error (command 'openapi.createNewThree' not found)

That seems like it might be a problem :-) - it explains why when I click on the button to create a new API file, nothing at all happens. It seems like my install is somehow broken, but I have uninstalled and re-installed.

@ak1394
Copy link
Collaborator

ak1394 commented Apr 12, 2021

Yes, indeed. The extension registers commands pretty early in the startup, so it looks like something gone seriously wrong with it.

One thing to check if you have RedHat YAML extension installed (the current version is v0.17.0)
If you have it installed, the next step is probably to run the OpenAPI extension under the debugger.

If you willing to try to debug it (which is pretty simple) I can provide instructions on how to do it.

@msennett9
Copy link
Author

Yes, I can try some debugging if you provide instructions - that would be great!

I was at version 0.16 of the RedHat YAML extension, but after upgrading and reloading, I am seeing the same results.

@ak1394
Copy link
Collaborator

ak1394 commented Apr 12, 2021

Cool, thanks! So to checkout the source code and build it you'll need Git and NodeJS (recent enough version, preferably v15). Steps to debug are:

  1. Clone the vscode-openapi sources:
git clone https://github.com/42Crunch/vscode-openapi.git
  1. Download the dependencies and build:
cd vscode-openapi
npm install
npm run vscode:prepublish
  1. Open the vscode-openapi folder, switch to "Run and Debug" view clicking bug and arrow icon on the left and check "Uncaught Exceptions" in the "Breakpoints" section at the bottom left.

  2. Click "Play" icon next to "Launch" text at the top right to start the debugger. This will create a new VS Code window running the extension under the debugger.

Hopefully when the extension starts, the exception will be thrown and it should switch you back to the debugger window with some information about the error. At this point it might be a good idea to do a screenshot and share it here.

Alternatively, before launching the extension under debugger you can open src/extension.ts and set a breakpoint by clicking at the left margin of the source file (it should put a red dot in there). The breakpoint should be set at line 30 (the start of the activate() function)

After setting the breakpoint, start the debugging session as above. It will open a new VS Code window, and then after a few seconds will switch you back to the debugger window with the line 30 highlighted.

From there you can execute the source code line by line by clicking the Step Over button (round arrow over a dot) or F10. When stepping over it should successfully execute all lines till at least line 57 or so (the end of this code block):

  context.subscriptions.push(...registerOutlines(context, cache));
  context.subscriptions.push(...registerCommands(cache));
  context.subscriptions.push(registerAddApprovedHost(context));

That's where it registers the commands. In any case I suspect it will show error before that. Again, if it happens please share the info (or the screenshot).

Hope the instructions are good enough, in any case let me know if you have questions.

@msennett9
Copy link
Author

Before I tried debugging, I decided to upgrade to the latest version of VS Code. I had 1.48.1 installed and upgraded to 1.55.1. When I did that, the OpenAPI editor started working again! Not sure if re-installing is what did the trick, or if there really is a dependency on the more recent version of VS Code. It does look like the version I was using was almost 10 months old.

I am also investigating the version of node that VS Code is using. I have 14.15.4 installed but VS Code reports using 12.18.3.

@ak1394
Copy link
Collaborator

ak1394 commented Apr 12, 2021

Ah, that's a good news indeed! I should've inquired about the version from the start, but majority of users runs latest so I've neglected asking :). The plugin is tested only with the relatively new versions, so I'm not surprised it didn't run on 1.48.1.

The version of Node doesn't matter in this case (as VS Code bundles it's own) it's only needed for initial setup for debugging (npm install, etc) so you shouldn't worry about that.

I guess that resolves the issue, I'm going to close the ticket but feel free to reopen if you need to.

@ak1394 ak1394 closed this as completed Apr 12, 2021
@alexthehurst
Copy link

For posterity: Today I had an issue that matches this description exactly: file not recognized, "New OpenAPI file" button does nothing, and "command 'openapi.createNewThree' not found" when trying to use OpenAPI commands. This happened for me after VS Code performed a self-update (I think) and asked me whether I trust the files in my workspace. Speculating, I'd guess that it has something to do with VS Code's security restrictions around the extension or the file.

Quitting and reopening VS Code resolved it and the extension is working correctly again.

By the way: thanks, maintainers! This extension is well-made and makes a big difference to my workflow.

@ak1394
Copy link
Collaborator

ak1394 commented Jun 24, 2021

Thanks for info @alexthehurst ! Recent update of VS Code has introduced concept of "Workspace Trust" which limits extensions which don't support working in "untrusted" workspaces. Our extension supports it already, but RedHat's YAML extension which we depend on does not yet. Once this issue is resolved redhat-developer/vscode-yaml#500 any prompts regarding workspace trust and our extension should go away. For the time being however, workspace must be "trusted" for the extension to work.

@kdipippo
Copy link

Ran into the same issue detailed above:

  • "No OpenAPI file selected" message, even though I copied this official OpenAPI example to validate
  • Nothing happened when "New OpenAPI file" button was clicked
  • Invoking "OpenAPI: Create new OpenAPI v3.0 file (YAML)" from the palette resulted in an error (command 'openapi.createNewThree' not found)

Uninstalling my version of VSCode and reinstalling the current version with Workspace Trust implementation was what did the trick! VSCode didn't prompt me for an update, so it wasn't obvious I was out of date with this significant feature. Thanks for thoroughly documenting how you both troubleshooted this issue 👍

@GuidoKuth
Copy link

Ran into the same issue today with VS Code 1.81.0, Node.js 16.17.1 and OpenAPI Extension Version 4.18.6

I did the steps metioned above to debug the issue. Here is the result:
image

Maybe someone can help and point me to a solution to resolve my problem.

@ak1394
Copy link
Collaborator

ak1394 commented Aug 10, 2023

Hi @GuidoKuth!

could you provide some more details regarding which instructions did you follow?

Looking at your screenshot it seems that you have cloned the extension source code and trying to run it under Debug?

@GuidoKuth
Copy link

Hi Anton,

yes, I followed the instructions you wrote at 12th April 2021.

@ak1394
Copy link
Collaborator

ak1394 commented Aug 11, 2023

Ok, the instructions are still good (there is an additional step now if you wanted to debug webviews like "TryIt" but you probably don't need it).

Looking at the trace though, the exception is seem to be caused by another extension - "ms-vscode.azure-account".

In any case, could you re-state what's your problem is, maybe you don't have to resort to debugging the extension?

If your OpenAPI file is not being recognized, could you try to create a new one by running the command "OpenAPI: Create new OpenAPI v3.0 file" from the command palette?

@GuidoKuth
Copy link

I tried several things now that I have read out of your previous answer.

I disbaled the extension ms-vscode.azure-account and all depending extensions. Restartet everything and started debugging OpenAPI Extension. The trace I got is still the same and it is produced immediately after running the extension in debug mode.

After that I loaded my empty repo and used the command palette and ran the command "OpenAPI: Create new OpenAPI v3.0 file". An error-message is shown "Command 'OpenAPI: Create new OpenAPI v3.0 file' resulted in an error" and underneath command 'openapi.createNewThree' not found.

@GuidoKuth
Copy link

In addition to my previous post I tried to disable even more extensions. But nothing changed the behaviour.

When the extension loads in debug-mode there is an error shown

Activating extension 'redhat.vscode-yaml' failed: Cannot find module 'c:\Users\gk.vscode\extensions\redhat.vscode-yaml-1.14.0\dist\extension'
Require stack:

  • c:\Users\gk\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\loader.js
  • c:\Users\gk\AppData\Local\Programs\Microsoft VS Code\resources\app\out\bootstrap-amd.js
  • c:\Users\gk\AppData\Local\Programs\Microsoft VS Code\resources\app\out\bootstrap-fork.js
  • .

and

Cannot activate the 'OpenAPI (Swagger) Editor' extension because its dependency 'YAML' failed to activate

@GuidoKuth
Copy link

I reinstalled the redhat.cscode-yaml extension but this changed also nothing

@ak1394
Copy link
Collaborator

ak1394 commented Aug 11, 2023

It looks like the extension has failed to start, and failed to register 'openapi.createNewThree' command. Could you restart your VS Code and the run "Developer: Show Logs..." -> "Extension Host" and share the output here?

@GuidoKuth
Copy link

Sure. Here it is
image

@ak1394
Copy link
Collaborator

ak1394 commented Aug 11, 2023

Thanks! That gives us more information, you can see there that redhat.vscode-yaml extension has failed to activate (and 42Crunch OpenAPI extension depends on it).

I'm not sure why did it fail to start, but to fix it I'd try to remove both OpenAPI extension and redhat.vscode-yaml, then re-install redhat.vscode-yaml, make sure it works, and then install 42Crunch OpenAPI extension.

If reinstalling redhat.vscode-yaml doesn't help, perhaps removing entire VS Code and installing it again would be a way to go

@GuidoKuth
Copy link

I uninstalled both extensions and reinstalled yaml extension. No error is shown, but the yaml extension is not activated, cause it is not used by any installed extension now. How do I check that it works?

@GuidoKuth
Copy link

I did some further tests and downgrading the yaml extension to version 1.13.0 solved the problem. Thanks for your help Anton.

@ak1394
Copy link
Collaborator

ak1394 commented Aug 11, 2023

You can open any YAML file and it should report that extension has been activated in logs ("Developer: Show Logs..." -> "Extension Host").

Also, you can hit Control-Shift-O and if the extension has been activated, it should show list of "symbols" in a window, otherwise it says "The active text editor does not provide symbol information"

@ak1394
Copy link
Collaborator

ak1394 commented Aug 11, 2023

@GuidoKuth I'm happy to help, and well done finding the issue!

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

5 participants