From 0c35b5ed5b7b9e8e7c91135323e72774328eb8e3 Mon Sep 17 00:00:00 2001 From: Graham Esau Date: Thu, 29 Aug 2024 17:05:13 +0100 Subject: [PATCH] Update docs and migration guide --- docs/0-migrating.md | 20 ++++++++++++++++++++ docs/_includes/attributes.md | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/0-migrating.md b/docs/0-migrating.md index 4ee936ad..499f32ca 100644 --- a/docs/0-migrating.md +++ b/docs/0-migrating.md @@ -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. diff --git a/docs/_includes/attributes.md b/docs/_includes/attributes.md index 25312d9a..5da084d8 100644 --- a/docs/_includes/attributes.md +++ b/docs/_includes/attributes.md @@ -310,7 +310,7 @@ Set the path to the schemars crate instance the generated code should depend on. -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 {