Skip to content

Commit

Permalink
fix: make sure the field and matching pattern are ordered correctly (#…
Browse files Browse the repository at this point in the history
…315)

* fix: make sure the field and matching pattern are ordered correctly

* fix: test repair

* fix: test repair v2
  • Loading branch information
aristosvo authored Jan 4, 2025
1 parent fce606f commit 3227b81
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/generator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ func (v *stringValidator) generate(out *codegen.Emitter) {
)
out.Indent(1)
out.Printlnf(
`return fmt.Errorf("field %%s pattern match: must match %%s", `+"`%s`"+`, "%s")`,
v.pattern, v.fieldName,
`return fmt.Errorf("field %%s pattern match: must match %%s", "%s", `+"`%s`"+`)`,
v.fieldName, v.pattern,
)
out.Indent(-1)
out.Printlnf("}")
Expand Down
4 changes: 2 additions & 2 deletions tests/data/validation/pattern/pattern.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestPattern(t *testing.T) {
{
desc: "myString does not match pattern",
data: `{"myString": "0x123456"}`,
wantErr: errors.New("field ^0x[0-9a-f]{10}\\.$ pattern match: must match MyString"),
wantErr: errors.New("field MyString pattern match: must match ^0x[0-9a-f]{10}\\.$"),
},
}

Expand Down

0 comments on commit 3227b81

Please sign in to comment.