Skip to content

Commit

Permalink
Update docs and migration guide
Browse files Browse the repository at this point in the history
  • Loading branch information
GREsau committed Aug 29, 2024
1 parent 21202f4 commit 0c35b5e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions docs/0-migrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,23 @@ fn my_transform2(schema: &mut Schema) {
let mut schema = schemars::schema_for!(str);
RecursiveTransform(my_transform2).transform(&mut schema);
```

## Changes to `#[validate(...)]` attributes

Since [adding support for `#[validate(...)]` attributes](https://graham.cool/schemars/v0/deriving/attributes/#supported-validator-attributes), the [Validator](https://github.com/Keats/validator) crate has made several changes to its supported attributes. Accordingly, Schemars 1.0 has updated its handling of `#[validate(...)]` attributes to match the latest version (currently 0.18.1) of the Validator crate - this removes some attributes, and changes the syntax of others:

- The `#[validate(phone)]`/`#[schemars(phone)]` attribute is removed. If you want the old behaviour of setting the "format" property on the generated schema, you can use `#[schemars(extend("format = "phone"))]` instead.
- The `#[validate(required_nested)]`/`#[schemars(required_nested)]` attribute is removed. If you want the old behaviour, you can use `#[schemars(required)]` instead.
- The `#[validate(regex = "...")]`/`#[schemars(regex = "...")]` attribute can no longer use `name = "value"` syntax. Instead, you can use:

- `#[validate(regex(path = ...)]`
- `#[schemars(regex(pattern = ...)]`
- `#[schemars(pattern(...)]` (Garde-style)

- Similarly, the `#[validate(contains = "...")]`/`#[schemars(contains = "...")]` attribute can no longer use `name = "value"` syntax. Instead, you can use:

- `#[validate(contains(pattern = ...))]`
- `#[schemars(contains(pattern = ...))]`
- `#[schemars(contains(...))]` (Garde-style)

As an alternative option, Schemars 1.0 also adds support for `#[garde(...)]` attributes used with the [Garde](https://github.com/jprochazk/garde) crate, along with equivalent `#[schemars(...)]` attributes. See [the documentation](https://graham.cool/schemars/deriving/attributes/#supported-validatorgarde-attributes) for a list of all supported attributes.
2 changes: 1 addition & 1 deletion docs/_includes/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ Set the path to the schemars crate instance the generated code should depend on.

</h3>

Sets properties specified by [validator attributes](#supported-validator-attributes) on items of an array schema. For example:
Sets properties specified by [validator attributes](#supported-validatorgarde-attributes) on items of an array schema. For example:

```rust
struct Struct {
Expand Down

0 comments on commit 0c35b5e

Please sign in to comment.