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

cannot access multiple field options of a field #64

Open
Shivam010 opened this issue Aug 3, 2019 · 4 comments
Open

cannot access multiple field options of a field #64

Shivam010 opened this issue Aug 3, 2019 · 4 comments

Comments

@Shivam010
Copy link
Contributor

Cannot access all the field options tagged in the field in proto, when the options are defined in oneOf type
See: https://github.com/Shivam010/protoc-gen-sample

When using this:

message Check {
    string field_1 = 1 [(main.rule1).type.one = "rule1.type.one", (main.rule1).type.two = "rule1.type.two"];
    string field_2 = 2 [(main.rule2).type.one = "rule2.type.one", (main.rule2).type.two = "rule2.type.two"];
    string field_3 = 3 [(main.rule2).type.two = "rule2.type.two", (main.rule2).type.one = "rule2.type.one"];
}

where rule1 and rule2 are 2 field options:

message Rule1 {
    String type = 1;
}
message Rule2 {
    oneof one_of {
        String type = 1;
    }
}
message String {
    string one = 1;
    string two = 2;
}

the retrieved options are for fields are:

field_1 one:"rule1.type.one" two:"rule1.type.two" 
field_2 two:"rule2.type.two" 
field_3 one:"rule2.type.one"

It turns out that in the case of oneOf a new message option is created each time. And hence, only second option value is received.

@adriangb
Copy link

adriangb commented Aug 5, 2020

Hi, just curious if this was ever looked at or resolved?

Shivam010 added a commit to Shivam010/protoc-gen-sample that referenced this issue Aug 5, 2020
@Shivam010
Copy link
Contributor Author

I don't think so.
I resolved the issue in my project by using a different approach. I had pushed it in my sample repo.

message Check {
    string field_1 = 1 [(main.rule1).type.one = "rule1.type.one", (main.rule1).type.two = "rule1.type.two"];
    // issue
    string field_2 = 2 [(main.rule2).type.one = "rule2.type.one", (main.rule2).type.two = "rule2.type.two"];
    string field_3 = 3 [(main.rule2).type.two = "rule2.type.two", (main.rule2).type.one = "rule2.type.one"];
    // solution
    string field_4 = 4 [(main.rule2).type = {one: "rule2.type.one" two: "rule2.type.two"}];
    string field_5 = 5 [(main.rule2).type = {two: "rule2.type.two" one: "rule2.type.one"}];
}

Follow https://github.com/Shivam010/protoc-gen-sample/blob/master/check.proto#L7-L15

@theruziev
Copy link

@Shivam010 Dude I only want to thank you because your sample repo helps me understand how to get options from messages.

@Shivam010
Copy link
Contributor Author

Happy that it was helpful for you! 🤗

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