grpc-ecosystem/grpc-gateway

openapiv2: Field options are not properly rendered for repeated fields

Open

#2,531 opened on Feb 9, 2022

View on GitHub
 (11 comments) (0 reactions) (1 assignee)Go (2,250 forks)batch import
buggood first issuehelp wantedopenapi

Repository metrics

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

Description

I need to generate swagger json using proto annotations. generated schema should look like this

"schema": {
              "type": "object",
              "example": {
                "product_id": ["8900099100000113079", "8900099100000082373"]
              },
              "properties": {
                "product_id": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "maxLength": 19,
                   "minLength": 1,
                   "pattern": "^[0-9]+$"
                  },
                  "description": "Only digits are allowed.",
                  "title": "Provide list of ids"           
                }
              }
            }

and the annotation added was something like this

message product { 
repeated string product_id=1[(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
                  pattern: "^[0-9]+$"
                  max_length: 19
                  min_length: 1
                  description: "Only digits are allowed."
    }];
}

But the problem is above annotation is generating schema like this

"schema": {
              "type": "object",
              "example": {
                "product_id": ["8900099100000113079", "8900099100000082373"]
              },
              "properties": {
                "product_id": {
                  "type": "array",
                  "items": {
                    "type": "string"                   
                  },
                  "description": "Only digits are allowed.",
                  "title": "Provide list of ids",
                   "maxLength": 19,
                   "minLength": 1,
                   "pattern": "^[0-9]+$"           
                }
              }
            }

which is not correct. We could not find the relevant example in a_bit_of_everything.proto.

Please help in adding the annotations.

Contributor guide