Skip to content

Allow #[schemars(...)] attributes when derive_unchecked is used - #265

Open
ychampion wants to merge 1 commit into
greyblake:masterfrom
ychampion:fix/allow-schemars-attr-with-derive-unchecked
Open

ychampion wants to merge 1 commit into
greyblake:masterfrom
ychampion:fix/allow-schemars-attr-with-derive-unchecked

Conversation

@ychampion

Copy link
Copy Markdown

Previously, partition_struct_attrs unconditionally rejected struct-level #[schemars(...)] attributes before #[nutype(...)] derive arguments were parsed, preventing #[schemars(...)] from being used alongside #[nutype(derive_unchecked(JsonSchema))] (for example with schemars 1.x).

Defer #[schemars(...)] validation to gen_nutype (alongside validate_serde_customization):

  • Forward #[schemars(...)] onto the generated struct when derive_unchecked(...) (or cfg_attr(..., derive_unchecked(...))) is present and nutype's built-in derive(JsonSchema) is not used.
  • Preserve the existing targeted error when derive(JsonSchema) is used or when no derive_unchecked derive is present.

Fixes #263

Previously, `partition_struct_attrs` rejected `#[schemars(...)]` before
parsing `#[nutype(...)]` arguments, blocking users who derive external
`schemars` (e.g. `schemars` 1.x) via `derive_unchecked(JsonSchema)`.

Forward `#[schemars(...)]` in `partition_struct_attrs` and validate it
in `gen_nutype` alongside `validate_serde_customization`, allowing
`#[schemars(...)]` when `derive_unchecked` is present (unconditionally
or via `cfg_attr`) and nutype's built-in `derive(JsonSchema)` is not
used, while keeping the existing error otherwise.

Fixes greyblake#263
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

schemars attribute rejection is over-zealous

1 participant