Skip to content

v2.9.0

Compare
Choose a tag to compare
@danielgtaylor danielgtaylor released this 18 Mar 16:02
· 366 commits to main since this release
c312351

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

New Contributors

Full Changelog: v2.8.0...v2.9.0