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

unable to parse pre-define field option #1

Open
sharonliao opened this issue Jun 9, 2022 · 2 comments
Open

unable to parse pre-define field option #1

sharonliao opened this issue Jun 9, 2022 · 2 comments

Comments

@sharonliao
Copy link

Added a pre-defined option in the test.proto, unable to generate the json file properly.
test.proto

syntax = "proto3";

import "google/protobuf/descriptor.proto";
import "google/api/field_behavior.proto";

package trinsic.protoc.gen.json.test;

// Test of a field extension
extend google.protobuf.FieldOptions {
  optional bool bool_option = 50000;
}

// Just a simple, hardworking enum
enum TestEnum {
  // Foo's value is 0. Foo indeed.
  FOO = 0;
  // Bar's value is 1. We don't like bar.
  BAR = 1;
}

// A message which is referenced as the field type for
// a field in another message
message TestReferencedMessage {
  // A string field
  string test_string_field = 1;
}

// A message
message TestMessage {
  // A message which is defined in another message
  message TestSubMessage {
    // A field in a message which is defined in another message
    // (...at the bottom of the sea)
    int64 test_sub_field = 1;
  }

  // A field with a type pointing to a message defined in another message.
  // This field also has a custom field option set on it.
  TestSubMessage test_sub_message_field = 1 [(bool_option) = false];

  // A field with a type pointing to a message defined externally
  TestReferencedMessage test_ref_field = 2;

  // A field with a primitive type
  int64 test_primitive_field = 3 [(google.api.field_behavior) = REQUIRED];

  // A field with an enum type
  TestEnum test_enum_field = 4;
}


// A message which is the input to a Method
message TestInputMessage {
  sint32 test_input_field = 1;
}

// A message which is the output of a Method
message TestOutputMessage {
  bool test_output_field = 2;
}

// A service
service TestService {
  // A method defined in a service
  rpc TestMethod              (TestInputMessage)             returns (TestOutputMessage);
}

Added a pre-defined option on line45
Line 45:
int64 test_primitive_field = 3 [(google.api.field_behavior) = REQUIRED];

Error msg:

--json_out: protoc-gen-json: Plugin output is unparseable: FAILED PARSING OPTIONS FOR FIELD trinsic.protoc.gen.json.test.TestMessage.test_primitive_field: [224 65 2]
@fundthmcalculus
Copy link
Contributor

We don't currently parse that [(google.api.field_behavior) = REQUIRED];, since it isn't used by our internal proto definitions.

@geel9
Copy link
Member

geel9 commented Jun 9, 2022

I'm guessing this has to do with the following combination of factors:

  • It's an option defined in an imported protobuf file, which itself might not be included in compilation when sent to the plugin (maybe?)
  • The type of the option value seems to be an enum, which I haven't put any effort into explicitly supporting (though the wire format should just be an integer type I assume)

At this point, this repo exists to serve Trinsic's needs for our documentation site -- we'll likely get around to resolving this issue once we run into it ourselves.

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

3 participants