@@ -744,7 +744,7 @@ func TestUnderOpenAPIExamplePayloadPath(t *testing.T) {
744744 want bool
745745 }{
746746 {"empty" , nil , false },
747- {"example_payload " , []string {"paths" , "get" , "responses" , "200" , "content" , "application/json" , "schema" , "example" }, true },
747+ {"example_root " , []string {"paths" , "get" , "responses" , "200" , "content" , "application/json" , "schema" , "example" }, false },
748748 {"nested_under_example_payload" , []string {"components" , "schemas" , "Foo" , "example" , "nested" }, true },
749749 {"examples_collection" , []string {"components" , "examples" }, false },
750750 {"example_object_entry" , []string {"components" , "examples" , "ReusableExample" }, false },
@@ -753,7 +753,7 @@ func TestUnderOpenAPIExamplePayloadPath(t *testing.T) {
753753 {"examples_data_value_payload" , []string {"components" , "examples" , "sample" , "dataValue" }, true },
754754 {"property_named_example" , []string {"components" , "schemas" , "Foo" , "properties" , "example" }, false },
755755 {"property_named_examples_value" , []string {"components" , "schemas" , "Foo" , "properties" , "examples" , "value" }, false },
756- {"real_example_after_property_example" , []string {"components" , "schemas" , "Foo" , "properties" , "example" , "example" }, true },
756+ {"real_example_after_property_example" , []string {"components" , "schemas" , "Foo" , "properties" , "example" , "example" }, false },
757757 }
758758 for _ , tt := range tests {
759759 t .Run (tt .name , func (t * testing.T ) {
@@ -1070,3 +1070,41 @@ components:
10701070 assert .False (t , rawRefs ["#/components/schemas/ShouldNotIndex" ])
10711071 assert .False (t , rawRefs ["#/components/schemas/ShouldNotIndexData" ])
10721072}
1073+
1074+ func TestSpecIndex_ExtractRefs_SchemaExampleRefIndexedButNestedPayloadRefsIgnored (t * testing.T ) {
1075+ spec := `openapi: 3.2.0
1076+ info:
1077+ title: Schema example refs
1078+ version: 1.0.0
1079+ components:
1080+ schemas:
1081+ UsesExampleRef:
1082+ type: object
1083+ example:
1084+ $ref: '#/components/examples/ReusableExample'
1085+ InlineExamplePayload:
1086+ type: object
1087+ example:
1088+ nested:
1089+ $ref: '#/components/schemas/ShouldNotIndex'
1090+ ShouldNotIndex:
1091+ type: object
1092+ examples:
1093+ ReusableExample:
1094+ value:
1095+ ok: true
1096+ `
1097+
1098+ var rootNode yaml.Node
1099+ _ = yaml .Unmarshal ([]byte (spec ), & rootNode )
1100+
1101+ idx := NewSpecIndexWithConfig (& rootNode , CreateOpenAPIIndexConfig ())
1102+
1103+ rawRefs := make (map [string ]bool )
1104+ for _ , ref := range idx .GetAllReferences () {
1105+ rawRefs [ref .RawRef ] = true
1106+ }
1107+
1108+ assert .True (t , rawRefs ["#/components/examples/ReusableExample" ])
1109+ assert .False (t , rawRefs ["#/components/schemas/ShouldNotIndex" ])
1110+ }
0 commit comments