You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When defining a serde default value for a field using a function results in the generated value being set as the default value for the schema.
This is troublesome for fields that contain random data, like Uuids, as you probably don't want to define a default value. Also the value will be different each time the schema is generated.
There probably needs to be an attribute to ignore the default value but still make the field optional in the schema.
Minimal example:
use schemars::{schema_for,JsonSchema};use serde::Deserialize;use uuid::Uuid;#[derive(Deserialize,JsonSchema)]pubstructExampleStruct{#[serde(default = "Uuid::new_v4")]uid:Uuid,}pubfnmain(){let schema = schema_for!(ExampleStruct);println!("{}", serde_json::to_string_pretty(&schema).unwrap());}
The easiest way to achieve this in schemars 1.0.0-alpha.3 is with the transform attribute, which can apply arbitrary modifications to generated schemas e.g.
When defining a serde default value for a field using a function results in the generated value being set as the default value for the schema.
This is troublesome for fields that contain random data, like
Uuid
s, as you probably don't want to define a default value. Also the value will be different each time the schema is generated.There probably needs to be an attribute to ignore the default value but still make the field optional in the schema.
Minimal example:
Output:
The text was updated successfully, but these errors were encountered: