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

repeated field validation along with item specific validations #251

Closed
Shivam010 opened this issue Jul 30, 2019 · 7 comments
Closed

repeated field validation along with item specific validations #251

Shivam010 opened this issue Jul 30, 2019 · 7 comments
Labels
Question Question about the library Stale Activity has stalled on this issue/pull-request

Comments

@Shivam010
Copy link

Shivam010 commented Jul 30, 2019

Hi, I want to check the unique and min_items validations along with the corresponding item validation in GoLang, but in doing so, I am getting an error:

Error while parsing option value for "repeated": Expected "{", found ".".

using:

message One {
     repeated string str = 1 [(validate.rules).repeated = {
        unique: true
        min_items: 1
        items.string: {
            min_len: 3
            max_len: 10
        }
    }];
}

And using something like passing more than one options for a field, I am getting another error:

Option "(validate.rules).repeated" was already set.

using:

message Two {
    repeated string str = 1 [(validate.rules).repeated.items.string = {min_len: 3 max_len: 10}, (validate.rules).repeated = {unique: true min_items: 1}];
}

Also, passing more than one validate field options in the array only uses the last one only.

message Three {
    repeated string str = 1 [(validate.rules).repeated.unique = true, (validate.rules).repeated.min_items = 1];
}

For object Three, only min_items validation will be generated.


Am I missing something or are these bugs?

@akonradi
Copy link
Contributor

akonradi commented Jul 31, 2019

Your first try is mostly right, just a small syntax error. Try this instead:

message One {
     repeated string str = 1 [(validate.rules).repeated = {
        unique: true
        min_items: 1
        items: {
            string: {
                min_len: 3
                max_len: 10
            }
        }
    }];
}

@Shivam010
Copy link
Author

Yes, my bad. I missed the basic syntax. Thanks @akonradi
But what about the validations in message Three?

@akonradi
Copy link
Contributor

I think you'll also need to use the expanded syntax to set more than one field. Try this:

message Three {
    repeated string str = 1 [(validate.rules).repeated = {
        unique: true
        min_items: 1
    }];
}

@Shivam010
Copy link
Author

Means, the plugin does not handle more than one options in the proto-options-array
Ok cool, I was asking out of curiosity, I don't think that would be required.
Thanks again

@rmichela rmichela added the Question Question about the library label Jul 31, 2019
@rodaine
Copy link
Member

rodaine commented Aug 2, 2019

Means, the plugin does not handle more than one options in the proto-options-array

This is a limitation of the protoc parser it turns out; you're essentially creating a new repeated message there in the annotation.

@Shivam010
Copy link
Author

This is a limitation of the protoc parser it turns out; you're essentially creating a new repeated message there in the annotation.

I think it is the limitation in protoc-gen-star, I tried a simple example with these options: link.
And used them in the same way as in above message Three: link.
And print the values in all the options here.

It turns out that in the case of oneOf a new message is created each time. And hence, it is not working in protoc-gen-validate

I have opened an issue in protoc-gen-star on this lyft/protoc-gen-star#64

@stale
Copy link

stale bot commented Sep 2, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Activity has stalled on this issue/pull-request label Sep 2, 2019
@stale stale bot closed this as completed Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Question about the library Stale Activity has stalled on this issue/pull-request
Projects
None yet
Development

No branches or pull requests

4 participants