gnostic icon indicating copy to clipboard operation
gnostic copied to clipboard

protoc-gen-openapi: POST method with empty body generates a required `requestBody`

Open Nomango opened this issue 3 years ago • 1 comments

Hi there. When I'm writing a POST method with an empty request body, protoc-gen-openapi generates a required requestBody

  rpc Logout(google.protobuf.Empty) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      post: "/api/logout"
      body: "*"
    };
  }
paths:
    /api/logout:
        post:
            requestBody:
                content:
                    application/json: {}
                required: true

Required empty body causes exceptions on swagger-ui. And I'm not sure which side is the problem.

Is it possible to provide an option to set requestBody.required? Like this:

--openapi_out=required_request_body=true/false/only_nonempty:.

Nomango avatar Jan 05 '23 06:01 Nomango

I think that we need to have switch case for such proto type and generate proper openapi without additional option

vtolstov avatar Jan 05 '23 07:01 vtolstov