Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 9 additions & 65 deletions aspnetcore/grpc/json-transcoding-openapi.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,17 @@
---
title: Use OpenAPI with gRPC JSON transcoding ASP.NET Core apps
title: gRPC JSON transcoding and OpenAPI
ai-usage: ai-assisted
author: jamesnk
description: Learn how to configure gRPC JSON transcoding to generate OpenAPI.
description: The `Microsoft.AspNetCore.Grpc.Swagger` package has been deprecated.
monikerRange: '>= aspnetcore-7.0'
ms.author: wpickett
ms.date: 02/19/2025
ms.date: 08/16/2026
uid: grpc/json-transcoding-openapi
---
# gRPC JSON transcoding documentation with Swagger / OpenAPI

[!INCLUDE[](~/includes/not-latest-version.md)]
# gRPC JSON transcoding and OpenAPI

By [James Newton-King](https://twitter.com/jamesnk)

[OpenAPI (Swagger)](https://swagger.io/specification/) is a language-agnostic specification for describing REST APIs. gRPC JSON transcoding supports generating OpenAPI from transcoded RESTful APIs. The [`Microsoft.AspNetCore.Grpc.Swagger`](https://www.nuget.org/packages/Microsoft.AspNetCore.Grpc.Swagger) package:

* Integrates gRPC JSON transcoding with [Swashbuckle](xref:tutorials/get-started-with-swashbuckle).
* Is experimental in .NET 7 to allow us to explore the best way to provide OpenAPI support.

## Get started

To enable OpenAPI with gRPC JSON transcoding:

1. Setup gRPC JSON transcoding by following the [getting started instructions](xref:grpc/json-transcoding#usage).
2. Add a package reference to [`Microsoft.AspNetCore.Grpc.Swagger`](https://www.nuget.org/packages/Microsoft.AspNetCore.Grpc.Swagger). The version must be 0.3.0-xxx or later.
3. Configure Swashbuckle in startup. The `AddGrpcSwagger` method configures Swashbuckle to include gRPC endpoints.

[!code-csharp[](~/grpc/json-transcoding-openapi/Program.cs?name=snippet_1&highlight=3-8,11-16)]

[!INCLUDE[](~/includes/package-reference.md)]

## Add OpenAPI descriptions from `.proto` comments

Generate OpenAPI descriptions from comments in the `.proto` contract, as in the following example:

```protobuf
// My amazing greeter service.
service Greeter {
// Sends a greeting.
rpc SayHello (HelloRequest) returns (HelloReply) {
option (google.api.http) = {
get: "/v1/greeter/{name}"
};
}
}

message HelloRequest {
// Name to say hello to.
string name = 1;
}
message HelloReply {
// Hello reply message.
string message = 1;
}
```

To enable gRPC OpenAPI comments:

1. Enable the XML documentation file in the server project with `<GenerateDocumentationFile>true</GenerateDocumentationFile>`.
2. Configure `AddSwaggerGen` to read the generated XML file. Pass the XML file path to `IncludeXmlComments` and `IncludeGrpcXmlComments`, as in the following example:

[!code-csharp[](~/grpc/json-transcoding-openapi/Program2.cs?name=snippet_1&highlight=6-8)]

To confirm that Swashbuckle is generating OpenAPI with descriptions for the RESTful gRPC services, start the app and navigate to the Swagger UI page:

![Swagger UI](~/grpc/json-transcoding-openapi/static/swaggerui.png)

## Additional resources

* <xref:grpc/json-transcoding>
* [OpenAPI homepage](https://www.openapis.org/)
* [`Swashbuckle.AspNetCore` GitHub repository](https://github.com/domaindrivendev/Swashbuckle.AspNetCore)
> [!IMPORTANT]
> The `Microsoft.AspNetCore.Grpc.Swagger` package described by this article was
> experimental and has been deprecated. It has no direct replacement. For more
> information, see [Deprecate Microsoft.AspNetCore.Grpc.Swagger (dotnet/aspnetcore #67134)](https://github.com/dotnet/aspnetcore/issues/67134).
Comment thread
wadepickett marked this conversation as resolved.
23 changes: 0 additions & 23 deletions aspnetcore/grpc/json-transcoding-openapi/Program.cs

This file was deleted.

27 changes: 0 additions & 27 deletions aspnetcore/grpc/json-transcoding-openapi/Program2.cs

This file was deleted.

Binary file not shown.
1 change: 0 additions & 1 deletion aspnetcore/grpc/json-transcoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ For installation and usage of grpc-gateway, see the [grpc-gateway README](https:
## Additional resources

* <xref:grpc/json-transcoding-binding>
* <xref:grpc/json-transcoding-openapi>
* <xref:grpc/browser>
* <xref:grpc/grpcweb>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ For installation and usage of grpc-gateway, see the [grpc-gateway README](https:
## Additional resources

* <xref:grpc/json-transcoding-binding>
* <xref:grpc/json-transcoding-openapi>
* <xref:grpc/browser>
* <xref:grpc/grpcweb>

Expand Down
2 changes: 1 addition & 1 deletion aspnetcore/release-notes/aspnetcore-7.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ gRPC JSON transcoding is an extension for ASP.NET Core that creates RESTful JSON
* ASP.NET Core gRPC apps to support both gRPC and RESTful JSON APIs without replicating functionality.
* Experimental support for generating OpenAPI from transcoded RESTful APIs by integrating with [Swashbuckle](xref:tutorials/get-started-with-swashbuckle).

For more information, see [gRPC JSON transcoding in ASP.NET Core gRPC apps](xref:grpc/json-transcoding?view=aspnetcore-7.0) and <xref:grpc/json-transcoding-openapi>.
For more information, see [gRPC JSON transcoding in ASP.NET Core gRPC apps](xref:grpc/json-transcoding?view=aspnetcore-7.0).

### gRPC health checks in ASP.NET Core

Expand Down
2 changes: 0 additions & 2 deletions aspnetcore/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1407,8 +1407,6 @@ items:
uid: grpc/json-transcoding
- name: HTTP rules and JSON
uid: grpc/json-transcoding-binding
- name: Swagger / OpenAPI
uid: grpc/json-transcoding-openapi
- name: Configuration
uid: grpc/configuration
- name: Authentication and authorization
Expand Down
Loading