Generation of invalid swagger specification
#1486 aperta il 24 giu 2020
Metriche repository
- Star
- (16.971 stelle)
- Metriche merge PR
- (Merge medio 8g 23h) (147 PR mergiate in 30 g)
Descrizione
🐛 Bug Report
Invalid swagger specifications are generated when trying to have get/patch requests on same path. The issue arises through the recommended use of field masks for the updating of a resource. This seems like a bit of a UX issue as the workaround is to not use field masks for update rpcs.
Apologies if there is a mistake in how I've added annotations to the protocol buffer service definition.
To Reproduce
Take the following protocol buffer definition:
syntax = "proto3";
option go_package = "github.com/bvwells/grpc-gateway-example/proto/beers";
import "google/api/annotations.proto";
import "google/protobuf/field_mask.proto";
message Thing {
string id = 1;
string name = 2;
}
message GetThingRequest {
string id = 1;
}
message GetThingResponse {
Thing thing = 1;
}
message UpdateThingRequest {
Thing thing = 1;
google.protobuf.FieldMask update_mask = 2;
}
message UpdateThingResponse {
Thing thing = 1;
}
// Thing service.
service ThingService {
// GetThing gets a thing given its ID.
rpc GetThing(GetThingRequest) returns (GetThingResponse) {
option (google.api.http) = {
get: "/api/v1/things/{id}"
};
}
// UpdateThing updates a thing given its ID.
rpc UpdateThing(UpdateThingRequest) returns (UpdateThingResponse) {
option (google.api.http) = {
patch: "/api/v1/things/{thing.id}"
body: "thing"
};
}
}
Run the protoc-gen-swagger generator:
protoc -I. --swagger_out=disable_default_errors=true,logtostderr=true:./ api.proto
Expected behavior
I would expect a valid swagger specification to be generated or an error in the generation process.
Actual Behavior
The swagger specification is generated successfully, but is invalid. Validating the swagger specification shows, e.g. in swagger editor (https://editor.swagger.io/)
Semantic error at paths./api/v1/things/{thing.id}
Equivalent paths are not allowed.
A similar issue can also be seen in https://github.com/grpc-ecosystem/grpc-gateway/blob/master/examples/internal/proto/examplepb/a_bit_of_everything.swagger.json which is an invalid swagger specification.
Let me know if you require any further information.