aspnetcore/grpc/json-transcoding-openapi.md
OpenAPI (Swagger) is a language-agnostic specification for describing REST APIs. gRPC JSON transcoding supports generating OpenAPI from transcoded RESTful APIs. The Microsoft.AspNetCore.Grpc.Swagger package:
To enable OpenAPI with gRPC JSON transcoding:
Microsoft.AspNetCore.Grpc.Swagger. The version must be 0.3.0-xxx or later.AddGrpcSwagger method configures Swashbuckle to include gRPC endpoints..proto commentsGenerate OpenAPI descriptions from comments in the .proto contract, as in the following example:
// 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:
<GenerateDocumentationFile>true</GenerateDocumentationFile>.AddSwaggerGen to read the generated XML file. Pass the XML file path to IncludeXmlComments and IncludeGrpcXmlComments, as in the following example:To confirm that Swashbuckle is generating OpenAPI with descriptions for the RESTful gRPC services, start the app and navigate to the Swagger UI page: