v2.9.0
Overview
String Length Validation
String length now counts the UTF8 runes in a string rather than using len(value)
, making for a more accurate count of the visible characters and being compatible with systems supporting unicode.
Add dependentRequired
Validation
You can now utilize JSON Schema's dependentRequired
validation which marks a field as required conditional on the presence of another field, for example:
type PaymentInfo struct {
Name string `json:"name" doc:"Billing name"`
Card int64 `json:"card,omitempty" doc:"Credit card number" dependentRequired:"address"`
Address string `json:"address,omitempty" doc:"Billing address"`
IBAN string `json:"iban,omitempty" doc:"Bank account ID for transfer"`
}
This requires a name
and then you can pass an iban
for a bank transfer or use a credit card. If the credit card is passed, then validation will fail unless an address is also passed.
Readonly Nested Structs
Nested structs can now utilize the readOnly
/ writeOnly
/ etc validation:
type Example struct {
Field struct {
Value string `json:"value"`
} `readOnly:"true"`
}
Better Pattern Errors
String pattern validation using regular expressions can now provide a user-friendly name so that the error says something like expected string to be alphabetical
instead of expected string to match pattern ^[a-zA-Z]+$
.
type Example struct {
Field string `json:"field" pattern:"^[a-zA-Z]+$" patternDescription:"alphabetical"`
}
Overriding Fields
A bug was fixed in the generated JSON Schema when overriding fields:
type One struct {
A string `json:"a"`
B string `json:"b"`
}
type Two struct {
One
B string `json:"-"`
}
This will result in a JSON Schema for Two
with only one field: a
.
What's Changed
- fix: length validation for utf8 strings by @maximdanilchenko in #298
- fix: issue 299 by @victoraugustolls in #304
- feat: dependent required tag by @victoraugustolls in #303
- chore(deps): bump google.golang.org/protobuf from 1.32.0 to 1.33.0 by @dependabot in #308
- chore(deps): bump google.golang.org/protobuf from 1.32.0 to 1.33.0 in /examples by @dependabot in #309
- fix: make dependent error deterministic by @danielgtaylor in #310
- feat: support dep required for map[any]any by @danielgtaylor in #312
- fix: authorizationUrl is only required for implicit/authcode by @danielgtaylor in #318
- doc: Add sponsor/funding info by @danielgtaylor in #319
- fix: skip param required check if SkipValidateParams is set by @danielgtaylor in #320
- Nested struct visibility by @CptKirk in #314
- feat(validation): flexible validation messages for pattern tag by @purin-dev in #323
New Contributors
- @maximdanilchenko made their first contribution in #298
- @victoraugustolls made their first contribution in #304
- @CptKirk made their first contribution in #314
- @purin-dev made their first contribution in #323
Full Changelog: v2.8.0...v2.9.0