Skip to content

Conversation

@antonkomarev
Copy link
Contributor

@antonkomarev antonkomarev commented Jan 6, 2025

Overview

This PR allows to use nested Request messages in service classes (fixes a bug linked below).

What this PR does / why we need it

syntax = "proto3";

package org.example;

service EmployeeService {
  rpc ListEmployee(ListEmployee.Request) returns (ListEmployee.Response);
}

message ListEmployee {
  message Request {
    string organization_id = 1;
  }

  message Response {
    oneof response {
      Result result = 1;
      string access_denied = 2;
    }

    message Result {
      repeated Employee employees = 1;
    }

    message Employee {
      string id = 1;
      string name = 2;
    }
  }
}

Will generate:

interface EmployeeService
{
    public function ListEmployee(
        array $ctx,
        \Org\Example\ListEmployee\Request $req
    ): \Org\Example\ListEmployee\Response;
}

Instead of:

interface EmployeeService
{
    public function ListEmployee(
        array $ctx,
        \Org\Example\Request $req
    ): \Org\Example\Response;
}

Special notes for your reviewer

Does this PR introduce a user-facing change?

Added support of nested Request & Response messages: https://github.com/twirphp/twirp/issues/201

@antonkomarev
Copy link
Contributor Author

antonkomarev commented Jan 6, 2025

@sagikazarmark I'm not good at Go, I'll be glad to get feedback, maybe there are better ways to do this.

@antonkomarev
Copy link
Contributor Author

I didn't found any tests, so haven't covered this case :(

@antonkomarev antonkomarev changed the title Fix nested request messages Fix nested Request & Response messages Jan 6, 2025
@sagikazarmark
Copy link
Member

sagikazarmark commented Jan 13, 2025

Yeah, we should probably add some better test cases for generated code.

In the meantime, can you give this patch a try? #208

(Updated PHP name generation based on the original compiler code: https://github.com/protocolbuffers/protobuf/blob/6e393fd79667597aac2bb42511fb30c31ff1611d/src/google/protobuf/compiler/php/names.cc)

(You can download a prebuilt artifact from this build: https://github.com/twirphp/twirp/actions/runs/12750830294)

@sagikazarmark sagikazarmark added kind/bug Something isn't working area/code-generator labels Jan 13, 2025
@antonkomarev
Copy link
Contributor Author

@sagikazarmark sure, will try to test your patch.

@sagikazarmark
Copy link
Member

@antonkomarev have you had a chance to test the patch?

@antonkomarev
Copy link
Contributor Author

@sagikazarmark not yet, plan to try it in the following days.

@antonkomarev
Copy link
Contributor Author

antonkomarev commented Jan 18, 2025

@sagikazarmark Yes, it's working as expected!

@antonkomarev antonkomarev deleted the fix-nested-request-messages branch January 18, 2025 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/code-generator kind/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import in service class is broken for nested request and response messages

2 participants