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

Protobuf field option can not be loaded after the toDescriptor call #3511

Open
Staniel opened this issue Jan 8, 2025 · 3 comments
Open

Protobuf field option can not be loaded after the toDescriptor call #3511

Staniel opened this issue Jan 8, 2025 · 3 comments

Comments

@Staniel
Copy link

Staniel commented Jan 8, 2025

I am trying out the custom option feature but I am not able to get it work. I am running 7.5.0 schema registry as well as client library version.
Here is my test schema:

syntax = "proto2";

package com.customtest;
option java_package = "com.customtest";
option java_outer_classname = "TestProto";

import "google/protobuf/descriptor.proto";

message CustomMessage1 {
  optional string test_string = 1 [ (field_custom1) = 123];
}

extend google.protobuf.FieldOptions {
  optional int32 field_custom1 = 1111;
}

Here is my test code:

        // Fetch the schema object of type ParsedSchema from some existing client code using the client library.
        ProtobufSchema protobufSchema = (ProtobufSchema) schema;
        Descriptors.Descriptor descriptor = protobufSchema.toDescriptor();
        for (Descriptors.FieldDescriptor field : descriptor.getFields()) {
          logger.atInfo().log("options: " + field.getOptions());
        }
        // No options showup in the result

Here is my debugging process and some result for troubleshooting:

  • I debug into the problem and it seems the field_custom1 option appear in the ProtobufSchema.schemaObj
  • however, after calling toDescriptor, the field option can not be retained.
  • On a further inspection, At this line the options showup but the field option can not be retained because the field option is evaluated for certain types including ctype, jstype, deprecated, etc. They are all null in my case and it can not be invoked to merge the options (reference code)

I am not sure if I miss something in this logic, the example I use is part of the test in this original PR. Do I need some special config to make this work?

@Staniel
Copy link
Author

Staniel commented Jan 8, 2025

@rayokota just want to check if you happen to have some knowledge on this?

@Staniel
Copy link
Author

Staniel commented Jan 8, 2025

Does it mean that only ctype, jstype or deprecated field options are supported?

@Staniel
Copy link
Author

Staniel commented Jan 8, 2025

I also find another PR https://github.com/confluentinc/schema-registry/pull/3254/files, but it seems adding a few more predefined options. Does it mean I can not define custom option fields myself?

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