Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

gvalid not supported required-without rule in struct field #2503

Closed
StrangeYear opened this issue Mar 7, 2023 · 5 comments
Closed

gvalid not supported required-without rule in struct field #2503

StrangeYear opened this issue Mar 7, 2023 · 5 comments
Assignees
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.

Comments

@StrangeYear
Copy link

type Order struct {
   ActorOrder       *ActorOrderReq  `p:"actor_order" v:"required-without:PlaceOrder"`
   PlaceOrder       *PlaceOrderReq  `p:"place_order"  v:"required-without:ActorOrder"`
}

Although I set the value of one field, the other field will still be verified.

problem file: gvalid_validator_check_struct.go

@StrangeYear
Copy link
Author

It is recommended to change the validator to the form of interface parameters so that users can use other third-party verification libraries. Personally, the library of goplaground/validator is easier to use.

@gqcn
Copy link
Member

gqcn commented Mar 7, 2023

@StrangeYear Please provide a copy of shortest codes for reproducing the error. A complete runnable program is best.

@StrangeYear
Copy link
Author

StrangeYear commented Mar 7, 2023

@StrangeYear Please provide a copy of shortest codes for reproducing the error. A complete runnable program is best.

type Foo struct {
	Bar *Bar `p:"bar" v:"required-without:Baz"`
	Baz *Baz `p:"baz" v:"required-without:Bar"`
}

type Bar struct {
	BarKey string `p:"bar_key" v:"required"`
}

type Baz struct {
	BazKey string `p:"baz_key" v:"required"`
}

func TestValidate(t *testing.T) {
	foo := &Foo{
		Bar: &Bar{BarKey: "value"},
	}
	err := gvalid.New().Data(foo).Bail().Run(context.Background())
	if err != nil {
		t.Fatal(err)
	}
}

Output:

The BazKey field is required

@gqcn gqcn added the bug It is confirmed a bug, but don't worry, we'll handle it. label Mar 8, 2023
@gqcn
Copy link
Member

gqcn commented Jul 20, 2023

@StrangeYear I'm dealing with this, but it needs some time.

@gqcn gqcn self-assigned this Feb 2, 2024
@gqcn gqcn added the wip label Feb 2, 2024
gqcn added a commit that referenced this issue Feb 4, 2024
@gqcn gqcn added done This issue is done, which may be release in next version. and removed wip labels Feb 4, 2024
@gqcn
Copy link
Member

gqcn commented Feb 4, 2024

#3299

@gqcn gqcn closed this as completed Feb 4, 2024
gqcn added a commit that referenced this issue Feb 5, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.
Projects
None yet
Development

No branches or pull requests

2 participants