grpc-ecosystem/grpc-gateway

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

Open

#991 ouverte le 12 août 2019

Voir sur GitHub
 (7 commentaires) (1 réaction) (0 assignés)Go (2 250 forks)batch import
enhancementhelp wanted

Métriques du dépôt

Stars
 (16 971 stars)
Métriques de merge PR
 (Merge moyen 8j 23h) (147 PRs mergées en 30 j)

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.

Guide contributeur