Skip to content

Commit 3e35bad

Browse files
committed
doc: add a test case documenting strange inference behavior
1 parent 7d11f2d commit 3e35bad

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

crates/doc/src/shape/inference.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,84 @@ mod test {
590590
);
591591
}
592592

593+
// This test documents the behavior in the corneer case where the
594+
// intersection of two object schemas forbids an enum property.
595+
#[test]
596+
fn test_enum_property_empty_intersection() {
597+
let shape = shape_from(
598+
r#"{
599+
"type": "object",
600+
"allOf": [
601+
{
602+
"properties": {
603+
"foo": {
604+
"type": "integer",
605+
"enum": [1, 2, 3]
606+
}
607+
}
608+
},
609+
{
610+
"properties": {
611+
"bar": { "type": "string" }
612+
},
613+
"additionalProperties": false
614+
}
615+
]
616+
}"#,
617+
);
618+
619+
let foo_shape = shape
620+
.object
621+
.properties
622+
.iter()
623+
.find(|p| p.name.as_ref() == "foo")
624+
.unwrap();
625+
626+
// The `type_` is empty because the property is not allowed to be present.
627+
// Note that the `enum_` is still `Some`, though the set of values is empty.
628+
insta::assert_debug_snapshot!(foo_shape, @r###"
629+
ObjProperty {
630+
name: "foo",
631+
is_required: false,
632+
shape: Shape {
633+
type_: ,
634+
enum_: Some(
635+
[],
636+
),
637+
title: None,
638+
description: None,
639+
reduction: Unset,
640+
provenance: Inline,
641+
default: None,
642+
secret: None,
643+
annotations: {},
644+
array: ArrayShape {
645+
additional_items: None,
646+
max_items: None,
647+
min_items: 0,
648+
tuple: [],
649+
},
650+
numeric: NumericShape {
651+
minimum: None,
652+
maximum: None,
653+
},
654+
object: ObjShape {
655+
additional_properties: None,
656+
pattern_properties: [],
657+
properties: [],
658+
},
659+
string: StringShape {
660+
content_encoding: None,
661+
content_type: None,
662+
format: None,
663+
max_length: None,
664+
min_length: 0,
665+
},
666+
},
667+
}
668+
"###);
669+
}
670+
593671
#[test]
594672
fn test_enum_type_extraction() {
595673
assert_eq!(

0 commit comments

Comments
 (0)