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

Visual Studio 2022 Endpoint Explorer Integration #196

Open
cmarkwick365 opened this issue Jun 28, 2023 · 15 comments
Open

Visual Studio 2022 Endpoint Explorer Integration #196

cmarkwick365 opened this issue Jun 28, 2023 · 15 comments

Comments

@cmarkwick365
Copy link

ApiEndPoints does not appear to work with VS 2022 Endpoint Explorer. Is it possible to enable this feature or is there a way to get it working out of the box?

@ardalis
Copy link
Owner

ardalis commented Jun 28, 2023

Hmm, the feature is still in preview, right?
https://devblogs.microsoft.com/visualstudio/web-api-development-in-visual-studio-2022/

I haven't used it myself but in the example shown in that article it's working with minimal API endpoints, though they claim it will also work with Controller-based endpoints. This library depends on Controllers, so any feature that discovers Controller-based endpoints should work with it. Do you have a sample you can share? Does the feature work with a vanilla controller class, but not with one that inherits from one of this package's base endpoint classes (which in turn inherit from controllers)?

@cmarkwick365
Copy link
Author

Thanks for your fast response Steve. I believe it's out of preview in VS 17.6, I think it relies upon the [ApiController] attribute.
This article may help:
https://dev.to/andytechdev/step-by-step-guide-testing-http-endpoints-in-visual-studio-2022-using-endpoints-explorer-fpb

@ardalis
Copy link
Owner

ardalis commented Jun 28, 2023

@cmarkwick365
Copy link
Author

I suspect it also utilizes the Http* attributes.

@ardalis
Copy link
Owner

ardalis commented Jun 28, 2023

Apparently the endpoints explorer menu option only appears if you first select a web project in solution explorer...

@emilun
Copy link

emilun commented Jul 5, 2023

I can open the "Endpoints Explorer" window and it shows the api project. However, no endpoints are discovered.

@Edgaras91
Copy link

Edgaras91 commented Aug 14, 2023

It may not be related, but for me, Endpoints Explorer only picks up if the controller class has [ApiController], but it doesn't pick up if it inherits a custom base controller that has [ApiController] attribute:

WORKS:

    [ApiController]
    [Route("accounts")]
    public class AccountController : ApiControllerBase

DOESN'T WORK:

    [Route("accounts")]
    public class AccountController : ApiControllerBase
    [ApiController]
    [Route("api/[controller]")]
    public abstract class ApiControllerBase : ControllerBase

I am using Visual Studio 2022 17.6.2 Professional

@ardalis
Copy link
Owner

ardalis commented Aug 15, 2023

Yeah, it definitely still has a ways to go to catch all of the endpoints in the project. They could also leverage the swagger file from the running project as a possible way to build their list of endpoints. Probably a good idea to leave feedback for them in their own repo and/or on social media where they'll see it (copy @VisualStudio). In the meantime I don't think it hurts anything if you add "extra" [ApiController] attributes to endpoints just for the sake of discoverability for the tool. I haven't tried it, though.

@johnholliday
Copy link

I've found that the Endpoints Explorer window only recognizes literal strings for routes. For example, the following declaration shows up in the Endpoints Explorer window:

public static class MyEndpoints {
  public static void MapMyEndpoints(this IEndpointRouteBuilder routes) {
    var group = routes.MapGroup("api/test");
    group.MapGet("/{id}", TestGetMethod);
}}

However, the following is invisible to the Endpoints Explorer window:

public static class MyEndpoints {
  private const string ApiBase = "api/Test";
  public static void MapMyEndpoints(this IEndpointRouteBuilder routes) {
    var group = routes.MapGroup(ApiBase);
    group.MapGet($"{ApiBase}/{id}", TestGetMethod);
}}

@ardalis
Copy link
Owner

ardalis commented Sep 11, 2023

Definitely seems like a bug on their end. Have you reported it with the feedback icon in VS?

@ardalis
Copy link
Owner

ardalis commented Sep 11, 2023

@cmarkwick365
Copy link
Author

cmarkwick365 commented Sep 12, 2023

Thanks for making me (in)famous Steve 👍
Lol

@johnholliday
Copy link

johnholliday commented Sep 12, 2023 via email

@ardalis
Copy link
Owner

ardalis commented Sep 12, 2023

Yeah reports via this method are more likely to be acted upon, it seems:
https://learn.microsoft.com/en-us/visualstudio/ide/how-to-report-a-problem-with-visual-studio?view=vs-2022

@ramiabughazaleh
Copy link

Hi.

I found the Visual Studio feedback item @johnholliday reported regarding discovering non-literal strings for routes here:
https://developercommunity.visualstudio.com/t/Endpoints-Explorer-fails-to-recognize-no/10463837

This issue is still marked as "Under Consideration"

I found a Visual Studio feedback item related to the issue @cmarkwick365 and @Edgaras91 encountered, regarding ApiControllerBase class inheritance, and the [ApiController] attribute here:
https://developercommunity.visualstudio.com/t/Bug-in-Endpoints-Explorer:-Controllers-n/10359760

This issue is marked as "Fixed In: Visual Studio 2022 version 17.7".

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

6 participants