Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path parameters that refer to request message subfields are not mapped #390

Open
sarnesjo opened this issue May 1, 2023 · 0 comments
Open

Comments

@sarnesjo
Copy link

sarnesjo commented May 1, 2023

protoc-gen-openapi does not map path parameters that refer to request message subfields (as in "/categories/{book_key.category}/books/{book_key.name}") as expected.

As an example, running protoc like this:

protoc library.proto \
  --proto_path=. \
  --proto_path=/path/to/googleapis \
  --openapi_out=. \
  --openapi_opt=enum_type=string \
  --openapi_opt=default_response=false

with this proto:

syntax = "proto3";

package library;

import "google/api/annotations.proto";

option go_package = "example.com/library";

service Library {
  rpc GetBook(GetBookRequest) returns (Book) {
    option (google.api.http) = {
      get: "/categories/{book_key.category}/books/{book_key.name}"
    };
  }
}

enum Category {
  CATEGORY_UNSPECIFIED = 0;
  FICTION = 1;
  NONFICTION = 2;
}

message BookKey {
  Category category = 1;
  string name = 2;
}

message GetBookRequest {
  BookKey book_key = 1;
}

message Book {
}

produces this output:

# Generated with protoc-gen-openapi
# https://github.com/google/gnostic/tree/master/cmd/protoc-gen-openapi

openapi: 3.0.3
info:
    title: Library API
    version: 0.0.1
paths:
    /categories/{book_key.category}/books/{book_key.name}:
        get:
            tags:
                - Library
            operationId: Library_GetBook
            parameters:
                - name: book_key.category
                  in: path
                  required: true
                  schema:
                    type: string
                - name: book_key.name
                  in: path
                  required: true
                  schema:
                    type: string
                - name: bookKey.category
                  in: query
                  schema:
                    enum:
                        - CATEGORY_UNSPECIFIED
                        - FICTION
                        - NONFICTION
                    type: string
                    format: enum
                - name: bookKey.name
                  in: query
                  schema:
                    type: string
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/Book'
components:
    schemas:
        Book:
            type: object
            properties: {}
tags:
    - name: Library

Note that book_key.category and book_key.name have not been mapped to their corresponding request message subfields, which therefore also show up as query parameters (bookKey.category and bookKey.name).

As far as I know, having path parameters refer to subfields is valid. It's mentioned in http.proto and is supported by the Envoy gRPC-JSON transcoder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant