-
Notifications
You must be signed in to change notification settings - Fork 2
Description
I don't find this statement in the RFC but given this error in the jtd Rust crate and the fact that a Schema is an enum and not a struct on the Rust side you can't have both Type and Enum on a schema.
Given I marshal the schema jtd.Schema{Enum: []string{"foo", "bar"} I will get the following output:
{
"definitions": null,
"metadata": null,
"nullable": false,
"ref": null,
"type": "",
"enum": [
"foo",
"bar"
],
"elements": null,
"properties": null,
"optionalProperties": null,
"additionalProperties": false,
"values": null,
"discriminator": "",
"mapping": null
}If I send this schema to a Rust application to be deserialized by the Rust crate this will result in a jtd::SerdeSchema with a type that is Some("") and the enum set. If I then try to convert the jtd::SerdeSchema to a jtd::Schema this will fail since this is not allowed.
fn main() {
let data = r#"{
"definitions": null,
"metadata": null,
"nullable": false,
"ref": null,
"type": "",
"enum": [
"foo",
"bar"
],
"elements": null,
"properties": null,
"optionalProperties": null,
"additionalProperties": false,
"values": null,
"discriminator": "",
"mapping": null
}"#;
let s: jtd::SerdeSchema = serde_json::from_str(data).unwrap();
let r = jtd::Schema::from_serde_schema(s);
let e = r.err().unwrap();
println!("{:?}: {}", e, e);
}InvalidForm: invalid combination of keywords in schemaThis would be solved by merging #5 but I wanted to add this issue to show a use case and a reason to why we would want to use omitempty.
This applies for at least Type, Discriminators and AdditionalProperties.
(The last one is a bit weird though, that should probably be fixed on the Rust side by ignoring false instead of using Optional<bool> but that's off topic for this issue)