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

Issue when using AddApiExplorer and JsonTranscoding #2500

Open
mcastagna-sa opened this issue Aug 9, 2024 · 0 comments
Open

Issue when using AddApiExplorer and JsonTranscoding #2500

mcastagna-sa opened this issue Aug 9, 2024 · 0 comments
Labels
question Further information is requested

Comments

@mcastagna-sa
Copy link

Hey guys, i'm having a problem with a project i'm working on and i wanted to see if i'm missing anything or maybe i've stumbled on a bug.

I have created a minimal project where i'm able to reproduce the behaviour, I'm goint to try to guide you pasting snippets of code here.

Program.cs

static void Main(string[] args)
 {
     var app = CreateHostBuilder(args).Build();

     app.UseRouting();

     app.MapControllers();

     app.MapGrpcService<GreeterService>();

     app.Run();
 }
  
 private static WebApplicationBuilder CreateHostBuilder(string[] args)
 {
     var builder = WebApplication.CreateBuilder(args);

     builder
         .WebHost.ConfigureKestrel((context, options) =>
         {
             options.ListenLocalhost(8080);
         });

     builder.Services.AddControllers();

     builder.Services.AddApiVersioning(options =>
          {
              options.ReportApiVersions = true;
          })
          .AddApiExplorer(options =>
          {
              options.GroupNameFormat = "'v'VVV";
              options.SubstituteApiVersionInUrl = true;                     
          });

     builder.Services
         .AddGrpc()
         .AddJsonTranscoding();

     return builder;
 }

V2Controller.cs

[ApiController]
[ApiVersion("2.0")]
[Produces("application/json")]
[Route("api/v{version:apiVersion}/controller/{param}")]
public class V2Controller : Controller
{
    [HttpGet]
    [Route("route")]
    public async Task<IActionResult> GetEndpoint()
    {
        return Ok("ok get v2");
    }
}

And greet.proto (This is the wiki example as you can see, just added the route i need to demostrate my point)

syntax = "proto3";

option csharp_namespace = "TestVersioningGRPC.Proto";
import "google/api/annotations.proto";

package greet;

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply) {
    option (google.api.http) = {        
      get: "/api/v1/controller/{name}/route"
    };
  }
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

message HelloReply {
  string message = 1;
}

When i run this program, and try to hit the endpoint v2 with postman everything goes as expected.

image

But, instead, if i call v1, which should be responded by the jsontranscode, i get 404.

image

I've tracked this down to the call of AddApiExplorer. If i remove that call i'm able to get the v1 as i should.

What do you think about this? Is this the expected behaviour? Am i doing something wrong? Is this a bug? If it is, is a bug in the jsontranscoding or asp.versioning library?

Thank you so much for your time and sorry the lenght of this post. Let me know if you need anything else that could help you answering this.

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

No branches or pull requests

1 participant