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

.NET9 preview's OpenAPI document generation doesn't work when transcoded from gRPC #58010

Closed
1 task done
python3js opened this issue Sep 22, 2024 · 2 comments
Closed
1 task done
Labels
area-grpc Includes: GRPC wire-up, templates feature-openapi ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved

Comments

@python3js
Copy link

python3js commented Sep 22, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Description:

I am using .NET 9 Preview's built-in support for OpenAPI document generation with gRPC JSON transcoding. However, the OpenAPI document generated contains an empty paths object when the transcoding is enabled. The document generates correctly (without empty paths) when I don't use the transcoding service.

I've followed the tutorial for gRPC JSON transcoding from .NET 8 (available here) and refactored it to incorporate .NET 9 Preview's built-in OpenAPI support (as described here).

However, the paths in the OpenAPI document remain empty.


Generated OpenAPI Document:

{
  "openapi": "3.0.1",
  "info": {
    "title": "Transcoding | v1",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "http://localhost:5204"
    }
  ],
  "paths": {},
  "components": {}
}

Program Code:

using Transcoding.Services;

var builder = WebApplication.CreateBuilder(args);

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

var app = builder.Build();

app.MapOpenApi();

app.MapGrpcService<GreeterService>();

app.Run();

Expected Behavior

I expect the OpenAPI document to populate the paths with the routes corresponding to the gRPC methods exposed via JSON transcoding, similar to how it works without the transcoding services.

Actual Behavior

When using gRPC JSON transcoding with Microsoft.AspNetCore.Grpc.JsonTranscoding, the generated OpenAPI document has empty paths. The issue only occurs when transcoding is enabled.

Steps To Reproduce

  1. Use the preview versions of Microsoft.AspNetCore.OpenApi and Microsoft.AspNetCore.Grpc.JsonTranscoding.
  2. Follow the instructions from the linked articles to enable gRPC JSON transcoding and OpenAPI document generation.
  3. Generate the OpenAPI document.

Exceptions (if any)

It does not throw any Exceptions. It just doesn't work as intended.

.NET Version

9.0.100-preview.7.24407.12

Anything else?

ASP.NET core 2.66.0

For reproducibility, I have created a repository that contains the setup where this issue occurs. You can find it here: https://github.com/python3js/Transcoding.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-grpc Includes: GRPC wire-up, templates label Sep 22, 2024
@captainsafia
Copy link
Member

@python3js Thanks for filling this issue!

OpenAPI support for gRPC JSON transcoding is supported via the Microsoft.AspNetCore.Grpc.Swagger package as documented in this page.

The package still takes a dependency on Swashbuckle (as of .NET 9). We hope to add support for the new Microsoft.AspNetCore.OpenApi package in the future but you'll still need to use the Microsoft.AspNetCore.Grpc.Swagger package to dd support for gRPC in this way.

@captainsafia captainsafia added the ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. label Sep 22, 2024
@python3js
Copy link
Author

@captainsafia Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-grpc Includes: GRPC wire-up, templates feature-openapi ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved
Projects
None yet
Development

No branches or pull requests

3 participants