Add transform = ...
attribute (#312)
This allows running arbitrary transforms on generated schemas when deriving `JsonSchema`
This commit is contained in:
parent
29067a0331
commit
14b06e71ba
10 changed files with 173 additions and 10 deletions
|
@ -49,6 +49,7 @@ TABLE OF CONTENTS
|
|||
- [`deprecated`](#deprecated)
|
||||
- [`crate`](#crate)
|
||||
- [`extend`](#extend)
|
||||
- [`transform`](#transform)
|
||||
- [Doc Comments (`doc`)](#doc)
|
||||
|
||||
</details>
|
||||
|
@ -326,10 +327,31 @@ Set on a container, variant or field to add properties (or replace existing prop
|
|||
The key must be a quoted string, and the value can be any expression that produces a type implementing `serde::Serialize`. The value can also be a JSON literal which can interpolate other values.
|
||||
|
||||
```plaintext
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(extend("simple" = "string value", "complex" = {"array": [1, 2, 3]}))]
|
||||
struct Struct;
|
||||
```
|
||||
|
||||
<h3 id="transform">
|
||||
|
||||
`#[schemars(transform = some::transform)]`
|
||||
|
||||
</h3>
|
||||
|
||||
Set on a container, variant or field to run a `schemars::transform::Transform` against the generated schema. This can be specified multiple times to run multiple transforms.
|
||||
|
||||
The `Transform` trait is implemented on functions with the signature `fn(&mut Schema) -> ()`, allowing you to do this:
|
||||
|
||||
```rust
|
||||
fn my_transform(schema: &mut Schema) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(transform = my_transform)]
|
||||
struct Struct;
|
||||
```
|
||||
|
||||
<h3 id="doc">
|
||||
|
||||
Doc Comments (`#[doc = "..."]`)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue