Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ updates:
directories:
- "/"
- "/rules/uuid"
- "/huma"
- "/gin"
- "/echo"
- "/integrations/huma"
- "/integrations/gin"
- "/integrations/echo"
- "/bench"
- "/examples/*"
schedule:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
go.sum
*/go.sum
rules/*/go.sum
integrations/*/go.sum

- name: Build
run: |
Expand Down Expand Up @@ -90,7 +91,7 @@ jobs:
cache-dependency-path: |
go.sum
rules/uuid/go.sum
huma/go.sum
integrations/*/go.sum
examples/*/go.sum

- name: Build and run the programs of the documentation and the skill
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ and a conversion that doesn't fit the field doesn't compile:
* Messages in English, German, Spanish, French and Russian with plural forms, the language of every request from the context, an `Accept-Language` middleware
* `problem`: the errors as `application/problem+json` of RFC 9457 with JSON pointers
* The rules as the keywords of JSON Schema, `vhuma.OpenAPI` puts them into the OpenAPI document of huma: the clients see `maxLength`, `format`, `enum` of the rules
* `github.com/insei/valigo/huma`, `github.com/insei/valigo/gin`, `github.com/insei/valigo/echo`: the rules of valigo in [huma](https://huma.rocks), [gin](https://gin-gonic.com) and [echo](https://echo.labstack.com)
* `github.com/insei/valigo/integrations/huma`, `github.com/insei/valigo/integrations/gin`, `github.com/insei/valigo/integrations/echo`: the rules of valigo in [huma](https://huma.rocks), [gin](https://gin-gonic.com) and [echo](https://echo.labstack.com)

# Performance
The same struct and rules, Intel Core i9-14900HX, Go 1.27.0, see [Performance](https://insei.github.io/valigo/latest/performance/):
Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The rules append their errors to one pooled buffer of the validation, and `Valid
| `rules/str`, `rules/num`, `rules/timex`, `rules/eq` | configurators of strings, numbers, times and comparable values built on `shared.Field[T]`, their conversions `str.Of`, `num.Of`, `num.Ptr`, `timex.Of`, `eq.Of`... and slice conversions |
| `problem` | the problem details of RFC 9457 |
| `github.com/insei/valigo/rules/uuid` | the separate module with the rules of `github.com/google/uuid`, the core doesn't depend on a uuid package |
| `github.com/insei/valigo/huma` | the separate module of the inputs of huma operations |
| `github.com/insei/valigo/integrations/huma`, `integrations/gin`, `integrations/echo` | the separate modules of huma, gin and echo |
| `translator` | translator, in-memory storage, built-in locales, `Accept-Language` middleware |

## Contributing
Expand Down
6 changes: 3 additions & 3 deletions docs/features/echo.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# echo

The module `github.com/insei/valigo/echo` validates the requests of [echo](https://echo.labstack.com) by valigo.
The module `github.com/insei/valigo/integrations/echo` validates the requests of [echo](https://echo.labstack.com) by valigo.

```bash
go get github.com/insei/valigo/echo@latest
go get github.com/insei/valigo/integrations/echo@latest
```

- `vecho.New(v)` is the `echo.Validator`: set `e.Validator = vecho.New(v)`, and `c.Validate(&req)` validates by the rules of valigo.
Expand All @@ -23,7 +23,7 @@ import (
"strings"

"github.com/insei/valigo"
vecho "github.com/insei/valigo/echo"
vecho "github.com/insei/valigo/integrations/echo"
"github.com/insei/valigo/rules/str"
"github.com/insei/valigo/shared"
"github.com/labstack/echo/v4"
Expand Down
6 changes: 3 additions & 3 deletions docs/features/gin.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# gin

The module `github.com/insei/valigo/gin` validates the requests of [gin](https://gin-gonic.com) by valigo.
The module `github.com/insei/valigo/integrations/gin` validates the requests of [gin](https://gin-gonic.com) by valigo.

```bash
go get github.com/insei/valigo/gin@latest
go get github.com/insei/valigo/integrations/gin@latest
```

- `vgin.New(v)` is the `binding.StructValidator` of gin: set `binding.Validator = vgin.New(v)`, and `c.ShouldBindJSON` and the other binding methods validate the requests by the rules of valigo. Slices are validated element by element, the location of an error has the index: `[1].email`.
Expand All @@ -26,7 +26,7 @@ import (
"github.com/gin-gonic/gin/binding"
"github.com/insei/fmap/v3"
"github.com/insei/valigo"
vgin "github.com/insei/valigo/gin"
vgin "github.com/insei/valigo/integrations/gin"
"github.com/insei/valigo/problem"
"github.com/insei/valigo/rules/str"
"github.com/insei/valigo/shared"
Expand Down
10 changes: 5 additions & 5 deletions docs/features/huma.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# huma

The module `github.com/insei/valigo/huma` validates the inputs of [huma](https://huma.rocks) operations by valigo. The errors are the error details of huma with its locations — `body.email`, `query.limit`, `path.id` — in the 422 response of huma, and the messages are translated to the languages of the `Accept-Language` header.
The module `github.com/insei/valigo/integrations/huma` validates the inputs of [huma](https://huma.rocks) operations by valigo. The errors are the error details of huma with its locations — `body.email`, `query.limit`, `path.id` — in the 422 response of huma, and the messages are translated to the languages of the `Accept-Language` header.

```bash
go get github.com/insei/valigo/huma@latest
go get github.com/insei/valigo/integrations/huma@latest
```

```go
import vhuma "github.com/insei/valigo/huma"
import vhuma "github.com/insei/valigo/integrations/huma"

var validator = valigo.New(valigo.WithFieldLocationNamingFn(vhuma.Location))

Expand Down Expand Up @@ -38,7 +38,7 @@ import (
"github.com/danielgtaylor/huma/v2"
"github.com/danielgtaylor/huma/v2/adapters/humago"
"github.com/insei/valigo"
vhuma "github.com/insei/valigo/huma"
vhuma "github.com/insei/valigo/integrations/huma"
"github.com/insei/valigo/rules/num"
"github.com/insei/valigo/rules/str"
)
Expand Down Expand Up @@ -134,7 +134,7 @@ import (
"github.com/danielgtaylor/huma/v2"
"github.com/danielgtaylor/huma/v2/adapters/humago"
"github.com/insei/valigo"
vhuma "github.com/insei/valigo/huma"
vhuma "github.com/insei/valigo/integrations/huma"
"github.com/insei/valigo/rules/str"
)

Expand Down
6 changes: 3 additions & 3 deletions docs/features/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ The separate modules for the frameworks.
| Page | What's inside |
|---|---|
| [JSON Schema](schema.md) | the rules as the keywords of JSON Schema for the generators of API schemas, `Constraints` |
| [huma](huma.md) | `github.com/insei/valigo/huma`: the rules in the `Resolve` of huma inputs with the locations of huma and in its OpenAPI document |
| [gin](gin.md) | `github.com/insei/valigo/gin`: the `binding.StructValidator` of gin and validation with the language of the request |
| [echo](echo.md) | `github.com/insei/valigo/echo`: the `echo.Validator` and validation with the language of the request |
| [huma](huma.md) | `github.com/insei/valigo/integrations/huma`: the rules in the `Resolve` of huma inputs with the locations of huma and in its OpenAPI document |
| [gin](gin.md) | `github.com/insei/valigo/integrations/gin`: the `binding.StructValidator` of gin and validation with the language of the request |
| [echo](echo.md) | `github.com/insei/valigo/integrations/echo`: the `echo.Validator` and validation with the language of the request |
1 change: 1 addition & 0 deletions docs/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Rules are still configured by pointers to the fields of the model, but the confi
|---|---|
| `github.com/insei/valigo/str`, `github.com/insei/valigo/num` | `github.com/insei/valigo/rules/str`, `github.com/insei/valigo/rules/num`, also `rules/eq` and `rules/timex` |
| `github.com/insei/valigo/uuid` of the core module | the separate module `github.com/insei/valigo/rules/uuid` |
| — | the integrations are the separate modules `github.com/insei/valigo/integrations/huma`, `integrations/gin`, `integrations/echo` |
| `b.String(&u.Name)` | `b.Field(&u.Name).As(str.Of)` |
| `b.Number(&u.Age)` | `b.Field(&u.Age).As(num.Of)` |
| `b.Number(&u.Score)` for `*int` | `b.Field(&u.Score).As(num.Ptr)` |
Expand Down
2 changes: 1 addition & 1 deletion docs/why-valigo.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ The rules of a slice check the slice itself and, by `Each`, every element with t

### Ready for HTTP APIs

The `problem` package writes the errors as `application/problem+json` of RFC 9457 with JSON pointers to the fields, the `github.com/insei/valigo/huma` module puts the rules into the inputs of huma operations with the locations of huma. See [HTTP problem details](features/problem.md) and [huma](features/huma.md).
The `problem` package writes the errors as `application/problem+json` of RFC 9457 with JSON pointers to the fields, the `github.com/insei/valigo/integrations/huma` module puts the rules into the inputs of huma operations with the locations of huma. See [HTTP problem details](features/problem.md) and [huma](features/huma.md).

### Errors that point to the field

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion echo/echo_test.go → integrations/echo/echo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/insei/valigo"
vecho "github.com/insei/valigo/echo"
vecho "github.com/insei/valigo/integrations/echo"
"github.com/insei/valigo/rules/str"
"github.com/insei/valigo/shared"
)
Expand Down
4 changes: 2 additions & 2 deletions echo/go.mod → integrations/echo/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/insei/valigo/echo
module github.com/insei/valigo/integrations/echo

go 1.27

replace github.com/insei/valigo => ../
replace github.com/insei/valigo => ../../

require (
github.com/insei/valigo v0.1.0
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion gin/gin_test.go → integrations/gin/gin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/insei/valigo"
vgin "github.com/insei/valigo/gin"
vgin "github.com/insei/valigo/integrations/gin"
"github.com/insei/valigo/rules/str"
"github.com/insei/valigo/shared"
)
Expand Down
4 changes: 2 additions & 2 deletions gin/go.mod → integrations/gin/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/insei/valigo/gin
module github.com/insei/valigo/integrations/gin

go 1.27

replace github.com/insei/valigo => ../
replace github.com/insei/valigo => ../../

require (
github.com/gin-gonic/gin v1.12.0
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions huma/go.mod → integrations/huma/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/insei/valigo/huma
module github.com/insei/valigo/integrations/huma

go 1.27

replace github.com/insei/valigo => ../
replace github.com/insei/valigo => ../../

require (
github.com/danielgtaylor/huma/v2 v2.39.1
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion huma/huma_test.go → integrations/huma/huma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/insei/valigo"
vhuma "github.com/insei/valigo/huma"
vhuma "github.com/insei/valigo/integrations/huma"
"github.com/insei/valigo/rules/num"
"github.com/insei/valigo/rules/str"
)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion huma/openapi_test.go → integrations/huma/openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/insei/valigo"
vhuma "github.com/insei/valigo/huma"
vhuma "github.com/insei/valigo/integrations/huma"
"github.com/insei/valigo/rules/eq"
"github.com/insei/valigo/rules/num"
"github.com/insei/valigo/rules/str"
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ plugins:
num.Ptr, timex.Of, eq.Of, str.Slice...), so the compiler checks the field types and the rule arguments
(Go 1.27 generic methods). Validation of valid objects doesn't allocate, absent values are skipped by all
rules except Required, errors have field locations, translated messages (en, de, es, fr, ru), stable codes
and named params; the problem package writes RFC 9457 problem details, the github.com/insei/valigo/huma
and named params; the problem package writes RFC 9457 problem details, the github.com/insei/valigo/integrations/huma
module validates huma inputs. The module path is github.com/insei/valigo.
sections:
Start:
Expand Down
2 changes: 1 addition & 1 deletion scripts/modules.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# The separate modules of the repository with their own go.mod, besides the core and the examples.
# CI and the scripts lint, test and cover every one of them.
MODULES="rules/uuid huma gin echo"
MODULES="rules/uuid integrations/huma integrations/gin integrations/echo"
6 changes: 3 additions & 3 deletions skills/valigo/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ func main() {

## gin

The module `github.com/insei/valigo/gin` (`vgin`): `binding.Validator = vgin.New(v)` makes `c.ShouldBindJSON` validate by valigo (messages in the default language, gin passes no request), `vgin.Validate(c, v, &req)` validates with the languages of `Accept-Language`; the error is `shared.Errors`, get it by `errors.As`.
The module `github.com/insei/valigo/integrations/gin` (`vgin`): `binding.Validator = vgin.New(v)` makes `c.ShouldBindJSON` validate by valigo (messages in the default language, gin passes no request), `vgin.Validate(c, v, &req)` validates with the languages of `Accept-Language`; the error is `shared.Errors`, get it by `errors.As`.

## echo

The module `github.com/insei/valigo/echo` (`vecho`): `e.Validator = vecho.New(v)` makes `c.Validate(&req)` validate by valigo (messages in the default language), `vecho.Validate(c, v, &req)` validates with the languages of `Accept-Language`; the error is `shared.Errors`.
The module `github.com/insei/valigo/integrations/echo` (`vecho`): `e.Validator = vecho.New(v)` makes `c.Validate(&req)` validate by valigo (messages in the default language), `vecho.Validate(c, v, &req)` validates with the languages of `Accept-Language`; the error is `shared.Errors`.

## huma

The module `github.com/insei/valigo/huma` (`vhuma`): `valigo.New(valigo.WithFieldLocationNamingFn(vhuma.Location))` gives the locations of huma (`body.email`, `query.limit`, `path.id`), `func (i *Input) Resolve(ctx huma.Context) []error { return vhuma.Resolve(ctx, validator, i) }` validates the input with the languages of `Accept-Language`.
The module `github.com/insei/valigo/integrations/huma` (`vhuma`): `valigo.New(valigo.WithFieldLocationNamingFn(vhuma.Location))` gives the locations of huma (`body.email`, `query.limit`, `path.id`), `func (i *Input) Resolve(ctx huma.Context) []error { return vhuma.Resolve(ctx, validator, i) }` validates the input with the languages of `Accept-Language`.

## Translations

Expand Down
Loading