@@ -267,4 +267,100 @@ mod tests {
267267 let missing = result. unwrap_err ( ) ;
268268 assert ! ( missing. contains( & "#/components/schemas/NonExistent" . to_string( ) ) ) ;
269269 }
270+
271+ #[ test]
272+ fn test_ref_integrity_components_traverses_all_ref_bearing_members ( ) {
273+ let mut spec = OpenApiSpec :: new ( "Test" , "1.0" ) ;
274+ let mut components = crate :: spec:: Components :: default ( ) ;
275+
276+ components. responses . insert (
277+ "badResponse" . to_string ( ) ,
278+ crate :: spec:: ResponseSpec {
279+ description : "bad" . to_string ( ) ,
280+ content : std:: collections:: BTreeMap :: from ( [ (
281+ "application/json" . to_string ( ) ,
282+ crate :: spec:: MediaType {
283+ schema : Some ( SchemaRef :: Ref {
284+ reference : "#/components/schemas/MissingFromResponse" . to_string ( ) ,
285+ } ) ,
286+ example : None ,
287+ } ,
288+ ) ] ) ,
289+ headers : std:: collections:: BTreeMap :: from ( [ (
290+ "X-Callback" . to_string ( ) ,
291+ crate :: spec:: Header {
292+ description : None ,
293+ schema : Some ( SchemaRef :: Ref {
294+ reference : "#/components/schemas/MissingFromResponseHeader" . to_string ( ) ,
295+ } ) ,
296+ } ,
297+ ) ] ) ,
298+ } ,
299+ ) ;
300+
301+ components. request_bodies . insert (
302+ "badRequestBody" . to_string ( ) ,
303+ crate :: spec:: RequestBody {
304+ description : None ,
305+ required : Some ( true ) ,
306+ content : std:: collections:: BTreeMap :: from ( [ (
307+ "application/json" . to_string ( ) ,
308+ crate :: spec:: MediaType {
309+ schema : Some ( SchemaRef :: Ref {
310+ reference : "#/components/schemas/MissingFromRequestBody" . to_string ( ) ,
311+ } ) ,
312+ example : None ,
313+ } ,
314+ ) ] ) ,
315+ } ,
316+ ) ;
317+
318+ components. headers . insert (
319+ "badHeader" . to_string ( ) ,
320+ crate :: spec:: Header {
321+ description : None ,
322+ schema : Some ( SchemaRef :: Ref {
323+ reference : "#/components/schemas/MissingFromHeader" . to_string ( ) ,
324+ } ) ,
325+ } ,
326+ ) ;
327+
328+ let mut callback_operation = crate :: spec:: Operation :: new ( ) ;
329+ callback_operation. request_body = Some ( crate :: spec:: RequestBody {
330+ description : None ,
331+ required : Some ( true ) ,
332+ content : std:: collections:: BTreeMap :: from ( [ (
333+ "application/json" . to_string ( ) ,
334+ crate :: spec:: MediaType {
335+ schema : Some ( SchemaRef :: Ref {
336+ reference : "#/components/schemas/MissingFromCallback" . to_string ( ) ,
337+ } ) ,
338+ example : None ,
339+ } ,
340+ ) ] ) ,
341+ } ) ;
342+
343+ let mut callback_path = crate :: spec:: PathItem :: default ( ) ;
344+ callback_path. post = Some ( callback_operation) ;
345+
346+ components. callbacks . insert (
347+ "badCallback" . to_string ( ) ,
348+ std:: collections:: BTreeMap :: from ( [ (
349+ "{$request.body#/callbackUrl}" . to_string ( ) ,
350+ callback_path,
351+ ) ] ) ,
352+ ) ;
353+
354+ spec. components = Some ( components) ;
355+
356+ let missing = spec
357+ . validate_integrity ( )
358+ . expect_err ( "should report all missing schema refs" ) ;
359+
360+ assert ! ( missing. contains( & "#/components/schemas/MissingFromResponse" . to_string( ) ) ) ;
361+ assert ! ( missing. contains( & "#/components/schemas/MissingFromResponseHeader" . to_string( ) ) ) ;
362+ assert ! ( missing. contains( & "#/components/schemas/MissingFromRequestBody" . to_string( ) ) ) ;
363+ assert ! ( missing. contains( & "#/components/schemas/MissingFromHeader" . to_string( ) ) ) ;
364+ assert ! ( missing. contains( & "#/components/schemas/MissingFromCallback" . to_string( ) ) ) ;
365+ }
270366}
0 commit comments