grpc-ecosystem/grpc-gateway

protoc-gen-swagger: No way to specify 0 as minimum on floating point values

Open

#991 opened on Aug 12, 2019

View on GitHub
 (7 comments) (1 reaction) (0 assignees)Go (2,250 forks)batch import
enhancementhelp wanted

Repository metrics

Stars
 (16,971 stars)
PR merge metrics
 (Avg merge 8d 23h) (147 merged PRs in 30d)

Description

Steps you follow to reproduce the error:

  1. Generate a swagger file from the following proto file:
syntax = "proto3";
package mytest;
import "protoc-gen-swagger/options/annotations.proto";
service MyTest {
  rpc MyTest (MyTestRequest) returns (MyTestResponse);
}
message MyTestRequest {}
message MyTestResponse {
  double value = 1  [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {
    minimum: 0,
    maximum: 36.22,
  }];
}

Basically I want to specify that value is valid for the [0, 36.22] range.

The JSON (snippet) output:

"mytest.MyTestResponse": {
    "properties": {
        "value": {
            "format": "double", 
            "maximum": 36.22, 
            "type": "number"
        }
    }, 
    "type": "object"
}

What did you expect to happen instead:

I expect the JSON file to look like:

"mytest.MyTestResponse": {
    "properties": {
        "value": {
            "format": "double", 
            "minimum": 0.0,
            "maximum": 36.22, 
            "type": "number"
        }
    }, 
    "type": "object"
}

The intent here is to be able to pass this to a tool that supports swagger and have it properly display that the minimum is 0.

What's your theory on why it isn't working:

I suspect since 0 is a "default" value, protoc-gen-swagger can't tell the difference between unset and set-to-default. And thus the minimum gets excluded.

Contributor guide