@@ -428,4 +428,63 @@ public function itCannotResolveExternalReferenceFromString(string $openAPIString
428428 (new Reader ([OpenAPIVersion::Version_3_0]))
429429 ->readFromString ($ openAPIString , FileFormat::Json);
430430 }
431+
432+ public static function provideOpenAPIWithInvalidReference (): Generator
433+ {
434+ yield 'missing forward slash after hash ' => [
435+ json_encode ([
436+ 'openapi ' => '3.0.0 ' ,
437+ 'info ' => ['title ' => 'API With Reference Object ' , 'version ' => '1.0.0 ' ],
438+ 'paths ' => [
439+ '/path ' => [
440+ 'get ' => [
441+ 'operationId ' => 'get-path ' ,
442+ 'responses ' => [
443+ 200 => [
444+ 'description ' => 'Successful Response ' ,
445+ 'content ' => [
446+ 'application/json ' => [
447+ 'schema ' => [
448+ '$ref ' => '#components/schemas/Test ' ,
449+ ],
450+ ],
451+ ],
452+ ],
453+ ],
454+ ],
455+ ],
456+ ],
457+ 'components ' => [
458+ 'schemas ' => [
459+ 'Test ' => [
460+ 'type ' => 'integer ' ,
461+ ]
462+ ]
463+ ]
464+ ]),
465+ ];
466+ }
467+
468+ #[Test]
469+ #[DataProvider('provideOpenAPIWithInvalidReference ' )]
470+ public function itCannotResolveInvalidReferenceFromAbsoluteFilePath (string $ openAPIString ): void
471+ {
472+ vfsStream::setup ();
473+ file_put_contents (vfsStream::url ('root/openapi.json ' ), $ openAPIString );
474+
475+ self ::expectExceptionObject (CannotRead::unresolvedReference (new CebeException \UnresolvableReferenceException ()));
476+
477+ (new Reader ([OpenAPIVersion::Version_3_0]))
478+ ->readFromAbsoluteFilePath (vfsStream::url ('root/openapi.json ' ));
479+ }
480+
481+ #[Test]
482+ #[DataProvider('provideOpenAPIWithInvalidReference ' )]
483+ public function itCannotResolveInvalidReferenceFromString (string $ openAPIString ,): void
484+ {
485+ self ::expectExceptionObject (CannotRead::unresolvedReference (new CebeException \UnresolvableReferenceException ()));
486+
487+ (new Reader ([OpenAPIVersion::Version_3_0]))
488+ ->readFromString ($ openAPIString , FileFormat::Json);
489+ }
431490}
0 commit comments