grpc-ecosystem/grpc-gateway

openapiv2: Field options are not properly rendered for repeated fields

Open

#2.531 aberto em 9 de fev. de 2022

Ver no GitHub
 (11 comments) (0 reactions) (1 assignee)Go (2.250 forks)batch import
buggood first issuehelp wantedopenapi

Métricas do repositório

Stars
 (16.971 stars)
Métricas de merge de PR
 (Mesclagem média 1d 4h) (141 fundiu PRs em 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.

Guia do colaborador