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 use map.keys.string.pattern and map.values.string.pattern rules together in a single annotation #160

Closed
kyoungkwon opened this issue Apr 4, 2019 · 5 comments
Labels
Bug Reports and/or fixes a bug Go Go language support Good First Issue Newcomer-friendly issue

Comments

@kyoungkwon
Copy link

When I use map.keys.string.pattern and map.values.string.pattern rules in a single annotation, I can't compile the generated code.
For example, I have the following message definition:

message Labels {
  map<string, string> label_map = 1
  [(validate.rules).map = { max_pairs: 128,
                            keys: {string: {min_len: 2, max_len:63, pattern: "^[a-z0-9A-Z._-]$"}},
                            values: {string: {min_len: 2, max_len:63, pattern: "^[a-z0-9A-Z._-]$"}}}];
}

Then the generated code have duplicate variables with the same name like this:

var _Labels_LabelMap_Pattern = regexp.MustCompile("^[a-z0-9A-Z._-]$")

var _Labels_LabelMap_Pattern = regexp.MustCompile("^[a-z0-9A-Z._-]$")

Which causes the build to fail with the following error:

pkg/proto/v1alpha/examples/labels.pb.validate.go:142:5: _Labels_LabelMap_Pattern redeclared in this block
        previous declaration at pkg/proto/v1alpha/examples/labels.pb.validate.go:140:5
@rodaine rodaine added Bug Reports and/or fixes a bug Go Go language support Good First Issue Newcomer-friendly issue labels Apr 4, 2019
@rodaine
Copy link
Member

rodaine commented Apr 4, 2019

Thanks for the report! This is indeed a bug.

@gnagel
Copy link

gnagel commented Oct 1, 2022

Ditto to this same issue, this is happening to me with the latest version v0.6.12/validate/validate.proto

@alexandreschoenwitz
Copy link

What is the reason was this closed as completed? The Bug is still there or not?

@elliotmjackson
Copy link
Contributor

Just a quick heads up – we've rolled out protovalidate, and it's free from the bug you mentioned here. Feel free to check it out and enjoy a smoother experience!

@chrispine
Copy link
Contributor

As explained in the README, this project is in maintenance mode. We recommend upgrading to protovalidate.

I'm going to go ahead and close this issue, but feel free to open one against protovalidate if needed. Thanks!

@chrispine chrispine closed this as not planned Won't fix, can't repro, duplicate, stale Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reports and/or fixes a bug Go Go language support Good First Issue Newcomer-friendly issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants