Skip to content

Commit

Permalink
Add docs about Issue #5241 (#5309)
Browse files Browse the repository at this point in the history
* docs(install-guide): update Go 1.24 tool directive usage

The previous installation guide relied on tools.go for tracking dependencies.
This update replaces it with the new tool directive introduced in Go 1.24.

Fixes #5254

* docs:add docs about "ref to reference unused messages for openapi.json inclusion"

Fixes #5241

* fix: update docs about using ref to reference unused messages

* fix: modify the document name and document location.

* fix: update docs suffix
  • Loading branch information
WwhdsOne authored Mar 8, 2025
1 parent 0bd409a commit e02fb22
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions docs/docs/mapping/using_ref_with_responses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Using arbitrary messages in response description

Assuming a protobuf file of the structure

```protobuf
syntax = "proto3";
package example.service.v1;
import "protoc-gen-openapiv2/options/annotations.proto";
service GenericService {
rpc GenericRPC(GenericRPCRequest) returns (GenericRPCResponse);
}
message GenericRPCRequest {
string id = 1;
}
message GenericRPCResponse {
string result = 1;
}
```

If you want your OpenAPI document to include a custom response for all RPCs defined in this protobuf file, you can add the following:

```protobuf
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
responses: {
key: "400"
value: {
description: "Returned when the request is malformed."
schema: {
json_schema: {ref: ".example.service.v1.GenericResponse"} // Must match the fully qualified name of the message
}
}
}
};
message GenericResponse {
repeated string resources = 1;
repeated string errors = 2;
}
```

When generating, you will see the following response included in your OpenAPI document:

```json
"400": {
"description": "Returned when the request is malformed.",
"schema": {
"$ref": "#/definitions/v1GenericResponse"
}
},
```

The annotation can also be specified per-rpc.

0 comments on commit e02fb22

Please sign in to comment.