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

Add example for how to use well known types with buf #64

Open
banool opened this issue Mar 29, 2023 · 1 comment
Open

Add example for how to use well known types with buf #64

banool opened this issue Mar 29, 2023 · 1 comment

Comments

@banool
Copy link

banool commented Mar 29, 2023

So in the buf model you use buf to build everything, including the file descriptor sets (usually). But how you access the well known types was a bit of a mystery to me until I did some digging. In short you need to add the protoc-wkt crate and then use the file descriptor set like this:

use protoc_wkt::google::protobuf::{FILE_DESCRIPTOR_SET as GOOGLE_PROTOBUF_FILE_DESCRIPTOR_SET};

fn myfunc() {
    let reflection_service = tonic_reflection::server::Builder::configure()
        // Note: It is critical that the file descriptor set is registered for every
        // file that the API proto depends on recursively. If you don't, compilation
        // will still succeed but reflection will fail at runtime.
        //
        // TODO: Add a test for this / something in build.rs, this is a big footgun.
        .register_encoded_file_descriptor_set(API_V2_FILE_DESCRIPTOR_SET)
        .register_encoded_file_descriptor_set(TRANSACTION_V1_TESTING_FILE_DESCRIPTOR_SET)
        .register_encoded_file_descriptor_set(UTIL_TIMESTAMP_FILE_DESCRIPTOR_SET)
        .register_encoded_file_descriptor_set(GOOGLE_API_V1_FILE_DESCRIPTOR_SET)
        .register_encoded_file_descriptor_set(GOOGLE_PROTOBUF_FILE_DESCRIPTOR_SET)
        .build()
        .context("Failed to build reflection service")?;
}

It'd be great to have an example that demonstrates how to use them. If I get some time any time soon I can take a crack at doing it myself 🤠

@jalaziz
Copy link

jalaziz commented Jul 17, 2023

I'm trying to setup the reflection service and it sure has been a pain to figure out where to get all the file descriptors.

In fact, I'm not sure how to get GOOGLE_API_V1_FILE_DESCRIPTOR_SET? Do I have to use --include-imports? In our case, we also use the protoc-gen-openapiv2 annotations and we're seeing reflection errors due to that.

While I appreciate protoc-gen-prost's approach to generating the FILE_DESCRIPTOR_SET, the default tonic-build approach does seem to make things slightly easier.

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

2 participants