grpc-ecosystem/grpc-gateway

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

Open

#991 建立於 2019年8月12日

在 GitHub 查看
 (7 留言) (1 反應) (0 負責人)Go (16,971 star) (2,250 fork)batch import
enhancementhelp wanted

描述

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.

貢獻者指南