Skip to content

protoc-gen-open generates a bad path for some starred paths #457

@asavageiv

Description

@asavageiv

Given this service definitions:

service WorkspaceService {
  rpc GetWorkspaceSetting(GetWorkspaceSettingRequest) returns (WorkspaceSetting) {
    option (google.api.http) = {get: "/api/v1/{name=workspace/settings/*}"};
    option (google.api.method_signature) = "name";
  }

  message GetWorkspaceSettingRequest {
    // The resource name of the workspace setting.
    // Format: workspace/settings/{setting}
    string name = 1 [
      (google.api.field_behavior) = REQUIRED,
      (google.api.resource_reference) = {type: "api.memos.dev/WorkspaceSetting"}
    ];
  }

I would expect a path to be generated like this:

paths:
    /api/v1/{name}:
        get:
            tags:
                - WorkspaceService
            description: Gets a workspace setting.
            operationId: WorkspaceService_GetWorkspaceSetting
            parameters:
                - name: name
                  in: path
                  description: The setting id.
                  required: true
                  schema:
                    type: string

This is the offending code:

// The starred path is assumed to be in the form "things/*/otherthings/*".
// We want to convert it to "things/{thingsId}/otherthings/{otherthingsId}".
for i := 0; i < len(parts)-1; i += 2 {
section := parts[i]
namedPathParameter := g.findAndFormatFieldName(section, inputMessage)
namedPathParameter = singular(namedPathParameter)
parts[i+1] = "{" + namedPathParameter + "}"
namedPathParameters = append(namedPathParameters, namedPathParameter)
}

Here is the description of the feature from the Transcoding proto:
https://github.com/googleapis/googleapis/blob/f8776fec04e336527ba7279d960105533a1c4e21/google/api/http.proto#L68

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions