2525use Swaggest \JsonSchema \Structure \Egg ;
2626use Swaggest \JsonSchema \Structure \ObjectItem ;
2727use Swaggest \JsonSchema \Structure \ObjectItemContract ;
28+ use Swaggest \JsonSchema \Structure \WithResolvedValue ;
2829
2930/**
3031 * Class Schema
@@ -702,6 +703,7 @@ private function processObject($data, Context $options, $path, $result = null)
702703 });
703704
704705 $ ref = $ refResolver ->resolveReference ($ refString );
706+ $ unresolvedData = $ data ;
705707 $ data = self ::unboolSchemaData ($ ref ->getData ());
706708 if (!$ options ->validateOnly ) {
707709 if ($ ref ->isImported ()) {
@@ -710,6 +712,7 @@ private function processObject($data, Context $options, $path, $result = null)
710712 }
711713 $ ref ->setImported ($ result );
712714 try {
715+ // Best effort dereference delivery.
713716 $ refResult = $ this ->process ($ data , $ options , $ path . '->$ref: ' . $ refString , $ result );
714717 if ($ refResult instanceof ObjectItemContract) {
715718 if ($ refResult ->getFromRefs ()) {
@@ -718,11 +721,28 @@ private function processObject($data, Context $options, $path, $result = null)
718721 $ refResult ->setFromRef ($ refString );
719722 }
720723 $ ref ->setImported ($ refResult );
724+ return $ refResult ;
721725 } catch (InvalidValue $ exception ) {
722726 $ ref ->unsetImported ();
723- throw $ exception ;
727+ $ skipValidation = $ options ->skipValidation ;
728+ $ options ->skipValidation = true ;
729+ $ refResult = $ this ->process ($ data , $ options , $ path . '->$ref: ' . $ refString );
730+ if ($ refResult instanceof ObjectItemContract) {
731+ if ($ refResult ->getFromRefs ()) {
732+ $ refResult = clone $ refResult ; // @todo check performance, consider option
733+ }
734+ $ refResult ->setFromRef ($ refString );
735+ }
736+ $ ref ->setImported ($ refResult );
737+ $ options ->skipValidation = $ skipValidation ;
738+
739+ if ($ result instanceof WithResolvedValue) {
740+ $ result ->setResolvedValue ($ refResult );
741+ }
742+
743+ // Proceeding with unresolved data.
744+ $ data = $ unresolvedData ;
724745 }
725- return $ refResult ;
726746 } else {
727747 $ this ->process ($ data , $ options , $ path . '->$ref: ' . $ refString );
728748 }
0 commit comments