go-proto-validators icon indicating copy to clipboard operation
go-proto-validators copied to clipboard

ProtoBuf Validator in grpc not able to set on google.protobuf.Int32Value and generates different name in swagger docs with workaround

Open sadief opened this issue 7 years ago • 0 comments

Golang ProtoBuf Validation question here - I'm trying to set validation on a limit field, however I need Limit to be a google.protobuf.Int32Value for validation and tests in our code. This doesn't work with validation however, so I've tried moving the LimitValue out of the Filter message, but this then generates a different name in the swagger docs which we can't use as the api information is already in production.

When I generate the protobuf files using this code:

message Filter {
  google.protobuf.Int32Value limit2 = 1;
}

The protobuf.swagger.json generates:

"parameters": [
          {
            "name": "limit2",
            "in": "query",
            "required": false,
            "type": "integer",
            "format": "int32"
          },

However if I use this:


message LimitValue {
  int32 value = 1 [(validator.field) = {int_gt: 0,int_lt: 101}];
}

message Filter {
  LimitValue limit = 1;
}

The generated code produces:


   "parameters": [
            {
            "name": "limit.value",
            "in": "query",
            "required": false,
            "type": "integer",
            "format": "int32"
          },

Any ideas on how to get around this?

Thanks!

sadief avatar Jul 23 '18 16:07 sadief