-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Merging swagger specs fails to use rpc comments #664
Comments
Have found the same issue. |
@lukasmalkmus fixed, thanks! |
I have a proto file which contains two services. The comments of the rpc methods present in second service gets copied from first service on swagger UI. Can somebody please tell me how to fix it ? |
@princejha95 That sounds like a bug, have you got your protofile and generated swagger file so we can see if there's an error? |
syntax = "proto3";
import "google/api/annotations.proto";
package test;
service SampleService1{
// Say Hello
rpc SayHello (HelloRequest) returns (HelloResponse){
option (google.api.http) = {
get : "/api/hello"
};
}
}
message HelloRequest{
// Hello message
string msg = 1;
}
message HelloResponse{
//Hello response
string res = 1;
}
service SampleService2{
//Say Bye
rpc SayBye (ByeRequest) returns (ByeResponse){
option (google.api.http) = {
get : "/api/bye"
};
}
}
message ByeRequest{
//Bye message
string msg = 1;
}
message ByeResponse{
//Bye response
string res = 1;
} This is the proto file. |
{
"paths": {
"/api/bye": {
"get": {
"tags": [
"SampleService2"
],
"operationId": "SayBye",
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/testByeResponse"
}
},
"404": {
"description": "Not Found",
"schema": {}
}
},
"parameters": [
{
"required": false,
"type": "string",
"name": "msg",
"description": "Bye message."
}
],
"summary": "Say Hello"
}
},
"/api/hello": {
"get": {
"tags": [
"SampleService1"
],
"operationId": "SayHello",
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/testHelloResponse"
}
},
"404": {
"description": "Not Found",
"schema": {}
}
},
"parameters": [
{
"required": false,
"type": "string",
"name": "msg",
"description": "Hello message."
}
],
"summary": "Say Hello"
}
}
},
"schemes": [
"http",
"https"
],
"tags": [
{
"name": "SampleService2",
"description": "Description"
},
{
"name": "SampleService1",
"description": "Description"
}
],
"basePath": "/",
"host": "localhost:3000",
"definitions": {
"testHelloResponse": {
"type": "object",
"properties": {
"res": {
"type": "string",
"title": "Hello response"
}
}
},
"testByeResponse": {
"type": "object",
"properties": {
"res": {
"type": "string",
"title": "Bye response"
}
}
}
},
"swagger": "2.0"
} This is the generated swagger json file. |
Yeah, that looks wrong. Could you open a separate issue with a minimal protofile which reproduces the error? I think something like the following should do: syntax = "proto3";
import "google/api/annotations.proto";
service SampleService1{
// Comment 1
rpc Method (Empty) returns (Empty){
option (google.api.http) = {
get : "/api/method"
};
}
}
service SampleService2{
// Comment 2
rpc Method (Empty) returns (Empty){
option (google.api.http) = {
get : "/api/method"
};
}
}
message Empty {} |
sure |
I have raised a new issue. Here's the link: |
I ran into an issue similar to this, would love to open a new issue if needed but thought I should start here since they related. I have a setup with multiple micro services each defined in their own .proto file. Code generation works well until I tried to combine my openAPI documentation using Using this command
|
Hi @bsakweson. Unfortunately, |
This is apparently still broken |
Steps for reproduction on latest release: #1387 |
Hi, I have same problem and this patch works for me. diff --git a/protoc-gen-swagger/genswagger/generator.go b/protoc-gen-swagger/genswagger/generator.go
index ecf1135..30fb7a7 100644
--- a/protoc-gen-swagger/genswagger/generator.go
+++ b/protoc-gen-swagger/genswagger/generator.go
@@ -168,7 +168,7 @@ func (g *generator) Generate(targets []*descriptor.File) ([]*plugin.CodeGenerato
for _, f := range targets {
if mergedTarget == nil {
mergedTarget = f
- } else {
+ } else if mergedTarget != f {
mergedTarget.Enums = append(mergedTarget.Enums, f.Enums...)
mergedTarget.Messages = append(mergedTarget.Messages, f.Messages...)
mergedTarget.Services = append(mergedTarget.Services, f.Services...) |
Hi @kentdotn, would you be willing to submit a PR with this fix? We can test it against our existing examples to make sure it doesn't break anything and hopefully finally fix this bug. Thanks! |
Sure! Here it is. |
* fix rpc comment generation against allow_merge * pass proper typeIndex base ond source file * add an example for merged output * update BUILD.bazel Fixes #664
@johanbrandhorst any chances this to be released in stable version soon? |
I'll tag a new patch release on v1. Please consider migrating to v2. |
I have two
proto
files:a.proto
:b.proto
:I tried to create a single swagger spec by using the
allow_merge
option. However, the generator removes some of the protobuf comments which get transformed into the endpoint description.Steps you follow to reproduce the error:
a.proto
andb.proto
What did you expect to happen instead:
Take a look at the separate specifications, the protobuf comments got transformed into endpoint descriptions:
a.swagger.json
:b.swagger.json
:This isn't true for the merged specification:
apidocs.swagger.json
:This spec misses the description of the
/v1/bars
endpoint.What's your theory on why it isn't working:
There seems to be a bug in the code which merges the two specs. I this its located around here:
grpc-gateway/protoc-gen-swagger/genswagger/generator.go
Lines 93 to 97 in a5b66c1
If merged to the leader, the code does not copy the comments.
The text was updated successfully, but these errors were encountered: