CarterCommunity / Carter

Carter is framework that is a thin layer of extension methods and functionality over ASP.NET Core allowing code to be more explicit and most importantly more enjoyable.
MIT License
2.05k stars 172 forks source link

Endpoints Not Visible in EndpointsApiExplorer #326

Closed johnholliday closed 10 months ago

johnholliday commented 10 months ago

Declaring minimal API endpoints in a Carter module hides them from the EndpointsApiExplorer.

jchannon commented 10 months ago

Does this sample app work for you?

https://github.com/CarterCommunity/Carter/blob/main/samples/CarterSample/Program.cs

On Fri, 1 Sep 2023 at 04:58, John Holliday @.***> wrote:

Declaring minimal API endpoints in a Carter module hides them from the EndpointsApiExplorer.

— Reply to this email directly, view it on GitHub https://github.com/CarterCommunity/Carter/issues/326, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAZVJXBOA4JXVQHS2Q5BTDXYFMPDANCNFSM6AAAAAA4G7FVK4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

johnholliday commented 10 months ago

The problem is that the EndpointsApiExplorer requires literal path strings.

Get Outlook for iOShttps://aka.ms/o0ukef


From: Jonathan Channon @.> Sent: Friday, September 1, 2023 5:39:14 PM To: CarterCommunity/Carter @.> Cc: John Holliday @.>; Author @.> Subject: Re: [CarterCommunity/Carter] Endpoints Not Visible in EndpointsApiExplorer (Issue #326)

Does this sample app work for you?

https://github.com/CarterCommunity/Carter/blob/main/samples/CarterSample/Program.cs

On Fri, 1 Sep 2023 at 04:58, John Holliday @.***> wrote:

Declaring minimal API endpoints in a Carter module hides them from the EndpointsApiExplorer.

— Reply to this email directly, view it on GitHub https://github.com/CarterCommunity/Carter/issues/326, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAZVJXBOA4JXVQHS2Q5BTDXYFMPDANCNFSM6AAAAAA4G7FVK4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

— Reply to this email directly, view it on GitHubhttps://github.com/CarterCommunity/Carter/issues/326#issuecomment-1703344983, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABIMPXCYD2TEZ6QWOBOVECDXYJIYFANCNFSM6AAAAAA4G7FVK4. You are receiving this because you authored the thread.Message ID: @.***>

jchannon commented 10 months ago

I don’t understand sorry

On Fri, 1 Sep 2023 at 22:55, John Holliday @.***> wrote:

The problem is that the EndpointsApiExplorer requires literal path strings.

Get Outlook for iOShttps://aka.ms/o0ukef


From: Jonathan Channon @.> Sent: Friday, September 1, 2023 5:39:14 PM To: CarterCommunity/Carter @.> Cc: John Holliday @.>; Author @.> Subject: Re: [CarterCommunity/Carter] Endpoints Not Visible in EndpointsApiExplorer (Issue #326)

Does this sample app work for you?

https://github.com/CarterCommunity/Carter/blob/main/samples/CarterSample/Program.cs

On Fri, 1 Sep 2023 at 04:58, John Holliday @.***> wrote:

Declaring minimal API endpoints in a Carter module hides them from the EndpointsApiExplorer.

— Reply to this email directly, view it on GitHub https://github.com/CarterCommunity/Carter/issues/326, or unsubscribe < https://github.com/notifications/unsubscribe-auth/AAAZVJXBOA4JXVQHS2Q5BTDXYFMPDANCNFSM6AAAAAA4G7FVK4>

. You are receiving this because you are subscribed to this thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub< https://github.com/CarterCommunity/Carter/issues/326#issuecomment-1703344983>, or unsubscribe< https://github.com/notifications/unsubscribe-auth/ABIMPXCYD2TEZ6QWOBOVECDXYJIYFANCNFSM6AAAAAA4G7FVK4>.

You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/CarterCommunity/Carter/issues/326#issuecomment-1703357030, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAZVJU7HPDKMZM54WF4BIDXYJKWZANCNFSM6AAAAAA4G7FVK4 . You are receiving this because you commented.Message ID: @.***>

johnholliday commented 10 months ago

The problem is not with Carter. The EndpointsApiExplorer cannot recognize paths that are declared with const or static strings. They have to be literal strings. In other words...

This works

public class ActorsModule : ICarterModule
{
  public void AddRoutes(IEndpointRouteBuilder app)
  {
    app.MapGet("/actors", GetAllActors).WithName("GetActors");
  }
}

This does not work. The Api explorer view will be empty.

public class ActorsModule : ICarterModule
{
  public static string ActorsRoute = "/actors";
  public void AddRoutes(IEndpointRouteBuilder app)
  {
    app.MapGet(ActorsRoute, GetAllActors).WithName("GetActors");
  }
}