Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Vieira Miguel authored and omissis committed Oct 30, 2023
1 parent 8fac7c1 commit 3c56aa4
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ While not finished, go-jsonschema can be used today. Aside from some minor featu
- [ ] `minimum`
- [ ] `exclusiveMinimum`
- [ ] String validation (§6.3)
- [ ] `maxLength`
- [ ] `minLength`
- [X] `maxLength`
- [X] `minLength`
- [ ] `pattern`
- [ ] Array validation (§6.4)
- [X] `items`
Expand Down
2 changes: 2 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
2 changes: 1 addition & 1 deletion pkg/generator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (v *stringValidator) generate(out *codegen.Emitter) {
}

if v.maxLength != 0 {
out.Printlnf(`if %slen(%s%s) >= %d {`, checkPointer, pointerPrefix, value, v.maxLength)
out.Printlnf(`if %slen(%s%s) > %d {`, checkPointer, pointerPrefix, value, v.maxLength)
out.Indent(1)
out.Printlnf(`return fmt.Errorf("field %%s length: must be <= %%d", "%s", %d)`, fieldName, v.maxLength)
out.Indent(-1)
Expand Down
4 changes: 2 additions & 2 deletions tests/data/validation/maxLength/maxLength.go

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

4 changes: 2 additions & 2 deletions tests/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ func TestMaxStringLength(t *testing.T) {
wantErr: nil,
},
{
desc: "myString too long",
desc: "myString has the max allowed length",
data: `{"myString": "hello"}`,
wantErr: errors.New("field myString length: must be <= 5"),
wantErr: nil,
},
{
desc: "myString not present",
Expand Down

0 comments on commit 3c56aa4

Please sign in to comment.