-
-
Notifications
You must be signed in to change notification settings - Fork 235
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
Support for omitting fields from the schema #27
Comments
This is already implemented - when I run use schemars::{schema_for, JsonSchema};
#[derive(JsonSchema)]
struct Foo {
#[schemars(skip)]
bar: String
}
fn main() {
let schema = schema_for!(Foo);
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
} It outputs: {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Foo",
"type": "object"
} Have you encountered a case where this doesn't happen? |
You're right it does, sorry for the noise. The actual issue I am running into is that all of the schemas generated by schemars do not have additionalProperties set to #[derive(JsonSchema)]
struct Foo {
#[schemars(skip)]
#[serde(other)]
extra_data: ...
} Is there a way to generically set the default of additionalProperties? |
The And in this case, #[derive(JsonSchema)]
struct Foo {
bar: String,
#[serde(flatten)]
extra: HashMap<String, Value>,
} Outputs: {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Foo",
"type": "object",
"required": [
"bar"
],
"properties": {
"bar": {
"type": "string"
}
},
"additionalProperties": true
} Unless you added |
Schemars doesn't set If you have a struct with |
Thanks, I did mean I am a bit confused why you are either setting In any case |
I'm going to close this since the underlying feature I am missing is already tracked in sourcecode and this thread is quite long-winded. |
I would like schemars to honor
serde(skip)
andschemars(skip)
to be able to omit internal datastructures. Ex:would generate a schema against which the input
{}
validates.The text was updated successfully, but these errors were encountered: