-
-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Override Serde for schema generation only #260
Comments
Overriding it with the use schemars::{schema_for, JsonSchema};
use serde::{Deserialize, Serialize};
#[derive(JsonSchema, Serialize, Deserialize)]
#[serde(rename_all(deserialize = "PascalCase"))] // for XML input
#[serde(rename_all(serialize = "snake_case"))] // JSON output
#[schemars(rename_all = "snake_case")]
pub struct MyStruct {
pub foo: i32,
}
fn main() {
let schema = schema_for!(MyStruct);
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
} And the generated schema always has the property |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We are using Schemars for schema generation in our project and it has been great!
I have a particular struct that is used to both deserialize from PascalCase XML and serialize to snake_case JSON. When creating a schema, the PascalCase is always used. Am I doing something wrong?
Example:
Edit: I also tried "overriding" Serde with a schemars declaration:
#[schemars(rename_all = "snake_case")]
But no luck
The text was updated successfully, but these errors were encountered: