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

Bug: Enum "in / not_in" in the Map #673

Open
yrcs opened this issue Oct 8, 2022 · 7 comments
Open

Bug: Enum "in / not_in" in the Map #673

yrcs opened this issue Oct 8, 2022 · 7 comments
Labels
Bug Reports and/or fixes a bug Go Go language support

Comments

@yrcs
Copy link

yrcs commented Oct 8, 2022

The closed #619 issue is still unresolved.

enum Order {
  ASC = 0;
  DESC = 1;
}

message PagingRequest {
  map<string, Order> orderBy = 1 [(validate.rules).map = {ignore_empty: true, keys: {string: {min_len: 1}}, values: {enum: {defined_only: true, in:[0, 1]}}}];
}
@elliotmjackson
Copy link
Contributor

Hi @yrcs, looking at the rule comparison chart in / not_in is not supported in maps at this stage. If you require them, id be happy to review a PR but at this stage we are focused on bugs and language support parity.

@yrcs
Copy link
Author

yrcs commented Oct 17, 2022

Hi @yrcs, looking at the rule comparison chart in / not_in is not supported in maps at this stage. If you require them, id be happy to review a PR but at this stage we are focused on bugs and language support parity.

OK! Just keep this issue open...

@elliotmjackson elliotmjackson added Enhancement Extend or improve functionality Feature Request Requesting a new feature be added labels Oct 17, 2022
@elliotmjackson elliotmjackson changed the title Enum "in / not_in" in the Map, compiler error: undeclared name: _PagingRequest_OrderBy_InLookup Feature Request: Enum "in / not_in" in the Map Oct 17, 2022
@haines
Copy link

haines commented Nov 29, 2022

looking at the rule comparison chart in / not_in is not supported in maps at this stage

I don't think it's specified in this comparison chart. The chart shows keys and values are supported; it doesn't list all the possible sub-rules that are supported within the keys and values.

I'd argue that this is a bug, not a lack of a feature, because pgv doesn't ignore in/not_in, or throw an error indicating that they are not supported - it exits successfully having generated code that then fails to compile.

@yrcs
Copy link
Author

yrcs commented Nov 30, 2022

@haines You're right, it's a bug. And I solved it temporarily by adding the following variables to the generated *.pb.validate.go file.

var _PagingRequest_OrderBy_InLookup = map[Order]struct{}{
    0: {},
    1: {},
}

@rolandcxc
Copy link

rolandcxc commented Dec 13, 2022

@elliotmjackson I have encountered the same problem with IDLs like this one.

message CreateTextRequest {
  map<string, string> texts = 1 [(validate.rules).map.keys.string = { in: [ "en", "zh" ] }];  
};

The definition of _CreateTextRequest_Texts_InLookup is missing from the generated go code.

	if _, ok := _CreateTextRequest_Texts_InLookup[key]; !ok {
		err := CreateTextRequestValidationError{
			field:  fmt.Sprintf("Texts[%v]", key),
			reason: "value must be in list [en zh]",
		}
		if !all {
			return err
		}
		errors = append(errors, err)
	}

Can this issue be fixed?

@m430
Copy link

m430 commented Mar 10, 2023

Same problem +1

@elliotmjackson
Copy link
Contributor

Good news! this has since been resolved in our protovalidate project. I'm pleased to let you know that protovalidate is where we're focusing our efforts for the future.

Given the improvements and advancements in protovalidate, I recommend considering migration to this newer version. It offers a more comprehensive and user-friendly experience within the Protobuf ecosystem.

@elliotmjackson elliotmjackson added the Bug Reports and/or fixes a bug label Aug 10, 2023
@chrispine chrispine removed Enhancement Extend or improve functionality Feature Request Requesting a new feature be added labels Feb 29, 2024
@chrispine chrispine changed the title Feature Request: Enum "in / not_in" in the Map Bug: Enum "in / not_in" in the Map Mar 1, 2024
@rodaine rodaine added the Go Go language support label Mar 14, 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
Projects
None yet
Development

No branches or pull requests

7 participants