We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi,
firstly thanks for this crate! Very useful!
As mentioned in the title, how can I programmatically remove the "format" from the json schema?
I'm using the v1.
use schemars::{ schema_for, JsonSchema}; #[derive(JsonSchema)] struct MyTest { value: i32, } fn main() { let schema = schema_for!(MyTest); println!("{}", serde_json::to_string_pretty(&schema).unwrap()); // output: // { // "$schema": "https://json-schema.org/draft/2020-12/schema", // "title": "MyTest", // "type": "object", // "properties": { // "value": { // "type": "integer", // "format": "int32" <-- this one! // } // }, // "required": [ // "value" // ] // } }
The text was updated successfully, but these errors were encountered:
Some issues
Sorry, something went wrong.
This is required to use schemars with ChatGPT's structured outputs. They don't support format and other validation keywords.
schemars
format
I found schemars after reading https://github.com/64bit/async-openai/blob/main/examples/structured-outputs-schemars/src/main.rs.
As a quick hack for my simple schema:
fn remove_property_format(schema: &mut schemars::schema::RootSchema) { let object_mut = schema.schema.object(); for property in object_mut.properties.values_mut() { if let schemars::schema::Schema::Object(obj) = property { obj.format = None; } } }
Used like this:
let mut schema = schema_for!(T); remove_property_format(&mut schema); let schema_value = serde_json::to_value(&schema)?;
Also note that you should use signed numbers, or schemars will insert "minimum": 0.0
"minimum": 0.0
No branches or pull requests
Hi,
firstly thanks for this crate! Very useful!
As mentioned in the title, how can I programmatically remove the "format" from the json schema?
I'm using the v1.
The text was updated successfully, but these errors were encountered: