Skip to content

struct-tag with validate is missing built-in rules #1367

Closed
@arxeiss

Description

@arxeiss

Describe the bug
struct-tag rule is validating https://pkg.go.dev/github.com/go-playground/validator/v10 rules, but some existing rules are considered unknown.

  • excluded_with
  • excluded_without

Quickly comparing https://github.com/go-playground/validator/blob/master/baked_in.go with https://github.com/mgechev/revive/blob/master/rule/struct_tag.go#L639 it seems there are much more

base64rawurl
ein
eq_ignore_case
eth_addr_checksum
eu_country_code
excluded_with
excluded_with_all
excluded_without
excluded_without_all
fieldcontains
fieldexcludes
gte
gtefield
gtfield
http_url
iso3166_1_alpha2_eu
iso3166_1_alpha3_eu
iso3166_1_alpha_numeric
iso3166_1_alpha_numeric_eu
iso3166_2
iso4217
iso4217_numeric
issn
ltefield
ltfield
md4
md5
ne_ignore_case
nefield
port
postcode_iso3166_alpha2
postcode_iso3166_alpha2_field
ripemd128
ripemd160
sha256
sha384
sha512
skip_unless
tiger128
tiger160
tiger192
udp_addr
uuid3_rfc4122
uuid4_rfc4122
uuid5_rfc4122
uuid_rfc4122
validateFn

To Reproduce
Steps to reproduce the behavior:

  1. I updated revive go install github.com/mgechev/revive@latest
  2. Run revive with struct-tag rule enabled and try to validate this structure
type property struct {
	Value         any        `json:"value" validate:"required_without=ExternalValue,excluded_with=ExternalValue"`
	ExternalValue string     `json:"external_value" validate:"required_without=Value,excluded_with=Value"`
}

Expected behavior
No error, those rules are not properly documented, but do exist in Validator codebase

Desktop (please complete the following information):

  • OS: Ubuntu / GitHub Ubuntu action runner
  • 1.24

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions