-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
split multiple types into anyOf subschema #20
Conversation
@@ -175,6 +176,20 @@ pub enum JsonSchemaType { | |||
Null, | |||
} | |||
|
|||
impl From<JsonSchemaType> for InstanceType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already have a conversion function for the opposite direction on crate::diff_walker::schemars_to_own
. The reasoning at the time was that we don't want to make the conversion public API, but I actually have no strong opinion on it.
please either:
- change this to be a simple function in
crate::diff_walker
- change
schemars_to_own
to be aimpl From<InstanceType> for JsonSchemaType
the choice is yours, but they should be next to each other to ensure they are consistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the latter idea
src/diff_walker.rs
Outdated
|
||
/// Split a schema into multiple schemas, one for each type in the multiple type. | ||
/// Returns the new schema and whether the schema was changed. | ||
fn split_types(schema_object: &mut SchemaObject) -> (SchemaObject, bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you can just do *schema_object = new_object
, and change function signature to (&mut SchemaObject) -> bool
, then you can avoid a clone()
in case you don't need to change the schema
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for the insight
This is a completely unrealistic schema (I hope), but I'm just curious, do you think it is possible to handle this case and produce no diff?
|
Thank you! |
We will need another internal conversion, though we should not convert them into {"properties": {"foo": {"anyOf": [{"type": "integer"}, {"type": "string"}]}}} Because converting "anyOf": [
{"properties": {"foo": {"type": "integer"}, "bar": {"type": "integer"}}},
{"properties": {"foo": {"type": "integer"}, "bar": {"type": "string"}}},
{"properties": {"foo": {"type": "string"}, "bar": {"type": "integer"}}},
] In this case, {"properties": {"foo": {"anyOf": [???]}, "bar": {"anyOf": [???]}}} |
Better conversion would be from "anyOf": [{
"properties": {
"foo": {
"type": ["integer", "string"]
},
"bar": {
"type": ["integer", "string"]
}
}
}] to "anyOf": [
{"properties": {"foo": {"type": "integer"}, "bar": {"type": "integer"}}},
{"properties": {"foo": {"type": "integer"}, "bar": {"type": "string"}}},
{"properties": {"foo": {"type": "string"}, "bar": {"type": "integer"}}},
{"properties": {"foo": {"type": "string"}, "bar": {"type": "string"}}},
] |
a fun problem to think about :) i am not sure if it is worth solving. if we go with the conversion from rhs to lhs as per your last comment, we should have some sort of limit in place to prevent combinatorial explosion and OOM. some good performance tests would be in https://github.com/getsentry/sentry-kafka-schemas/ |
Closes #16