grpc-ecosystem / grpc-gateway

gRPC to JSON proxy generator following the gRPC HTTP spec

Home Page:https://grpc-ecosystem.github.io/grpc-gateway/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Document about how to mark an arrray field as required in an extra openapi config file?

mousimin opened this issue Β· comments

πŸ“š Documentation

I have a simple proto file:

message GetTokenRequest {
  string hostname = 1 [(buf.validate.field).required = true, (buf.validate.field).string.hostname = true ];
  repeated string buckets = 2 [(buf.validate.field).repeated.min_items = 1];;
}

And I want to add an extra openapi file to help to generate the swagger file:

openapiOptions:
  field:
    - field: api.user.GetTokenRequest.hostname
      option:
        required: ["hostname"]
    - field: api.user.GetTokenRequest.buckets
      option:
        required: ["buckets"]

After run "buf generate proto" command, I found the hostname field was marked as required, but the buckets field was not, do we have a document which describes how to config an array field as required?
The generated swagger file:

"parameters": [
  {
    "name": "hostname",
    "description": "hostname is the name of which you want to acquire join token",
    "in": "query",
    "required": true,
    "type": "string"
  },
  {
    "name": "buckets",
    "description": "bucket is the name for the cos-agent instance using this token sneds telemetry data to",
    "in": "query",
    "required": false,
    "type": "array",
    "items": {
      "type": "string",
      "required": [
        "buckets"
      ]
    },
    "collectionFormat": "multi"
  }
]

Hm, I don't think so. There might be a bug here, but I'd appreciate if you could dig around a bit to find out. Perhaps this could be a doc contribution or a bug fix, or both :).