grpc-ecosystem/grpc-gateway

protoc-gen-openapiv2: don't emit body objects containing only nested path parameters

Open

#2.624 aberto em 4 de abr. de 2022

Ver no GitHub
 (8 comments) (3 reactions) (0 assignees)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

🚀 Feature

When path parameters are all part of a message in the body protoc-gen-openapiv2 emits a body property that is an empty object. While technically the field id is selected by body: "*" its sole field value is a path parameter and id is emitted as body object without properties.

service EntityService {
  rpc DeleteEntity(DeleteEntityRequest) returns (DeleteEntityResponse) {
    option (google.api.http) = {
      delete: "/entities/{id.value}"
      body: "*"
    };
  }
}

// message Entity {
//      EntityId id = 1;
//      etc.
// }

message EntityId {
        string value = 1;
}

message DeleteEntityRequest {
        EntityId id = 1;
        string other_field = 2;
}

message DeleteEntityResponse {}
    "/entities/{id.value}": {
      "delete": {
        "operationId": "EntityService_DeleteEntity",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/testingDeleteEntityResponse"
            }
          }
        },
        "parameters": [
          {
            "name": "id.value",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "object"     <---
                },
                "otherField": {
                  "type": "string"
                }
              }
            }
          }
        ]
      }
    }

Guia do colaborador