dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
34.59k stars 9.79k forks source link

Microsoft.AspNetCore.Grpc.Swagger doesn't respect WriteEnumsAsIntegers for request contracts #55733

Open abbottdev opened 2 weeks ago

abbottdev commented 2 weeks ago

Is there an existing issue for this?

Describe the bug

When using the gRPC transcoding package, in combination with the gRPC swagger definitions, the generated documentation is incorrect when using enums.

I've spent some time narrowing this down and believe I've reproduced the behaviour - it appears to be when using an enum in a .proto file. If an enum is only used in a response contract, then the generated swagger correctly states the response type to be a string type enum.

However, when an enum is used in a request contract, then the swagger type is created as an integer incorrectly: image

Generated from the following .proto file: greet.proto.txt

Expected Behavior

When using an enum in a request message for a gRPC transcoded API, the generated swagger definition should show that enum as a string when WriteEnumsAsIntegers is false.

Steps To Reproduce

I've created a repo here that demonstrates the issue: https://github.com/abbottdev/grpc-swagger-repo

This change may be related to https://github.com/dotnet/aspnetcore/issues/51036

If you clone the repo, dotnet run and browse to the swagger site: http://localhost:5122/swagger/ you'll see the ResponseOnlyEnum generated type is a string, but the RequestOnlyEnum and SharedEnum are both created as int32

Exceptions (if any)

No response

.NET Version

8.0

Anything else?

Asp.NET Core 8.0.5 and associated packages