@@ -40,12 +40,12 @@ class Schema extends JsonSchema implements MetaHolder
4040 const VERSION_DRAFT_06 = 6 ;
4141 const VERSION_DRAFT_07 = 7 ;
4242
43- const REF = '$ref ' ;
44- const ID = '$id ' ;
45- const ID_D4 = 'id ' ;
43+ const PROP_REF = '$ref ' ;
44+ const PROP_ID = '$id ' ;
45+ const PROP_ID_D4 = 'id ' ;
4646
4747 // Object
48- /** @var Properties|Schema[]|Schema */
48+ /** @var null| Properties|Schema[]|Schema */
4949 public $ properties ;
5050 /** @var Schema|bool */
5151 public $ additionalProperties ;
@@ -106,7 +106,7 @@ public static function import($data, Context $options = null)
106106 $ options = new Context ();
107107 }
108108
109- // $options->applyDefaults = false; // todo check infinite recursion on items, additionalProperties, etc...
109+ $ options ->applyDefaults = false ;
110110
111111 if (isset ($ options ->schemasCache ) && is_object ($ data )) {
112112 if ($ options ->schemasCache ->contains ($ data )) {
@@ -120,7 +120,7 @@ public static function import($data, Context $options = null)
120120
121121 // string $data is expected to be $ref uri
122122 if (is_string ($ data )) {
123- $ data = (object )array (self ::REF => $ data );
123+ $ data = (object )array (self ::PROP_REF => $ data );
124124 }
125125
126126 $ data = self ::unboolSchema ($ data );
@@ -302,8 +302,7 @@ private function processString($data, $path)
302302 if ($ this ->format !== null ) {
303303 $ validationError = Format::validationError ($ this ->format , $ data );
304304 if ($ validationError !== null ) {
305- if ($ this ->format === "uri " && substr ($ path , -3 ) === ':id ' ) {
306- } else {
305+ if (!($ this ->format === "uri " && substr ($ path , -3 ) === ':id ' )) {
307306 $ this ->fail (new StringException ($ validationError ), $ path );
308307 }
309308 }
@@ -564,7 +563,6 @@ private function processObject($data, Context $options, $path, $result = null)
564563 if ($ this ->useObjectAsArray ) {
565564 $ result = array ();
566565 } elseif (!$ result instanceof ObjectItemContract) {
567- //$result = $this->makeObjectItem($options);
568566 //* todo check performance impact
569567 if (null === $ this ->objectItemClass ) {
570568 $ result = new ObjectItem ();
@@ -604,10 +602,10 @@ private function processObject($data, Context $options, $path, $result = null)
604602 // @todo better check for schema id
605603
606604 if ($ import
607- && isset ($ data ->{Schema::ID_D4 })
605+ && isset ($ data ->{Schema::PROP_ID_D4 })
608606 && ($ options ->version === Schema::VERSION_DRAFT_04 || $ options ->version === Schema::VERSION_AUTO )
609- && is_string ($ data ->{Schema::ID_D4 }) /*&& (!isset($this->properties['id']))/* && $this->isMetaSchema($data)*/ ) {
610- $ id = $ data ->{Schema::ID_D4 };
607+ && is_string ($ data ->{Schema::PROP_ID_D4 }) ) {
608+ $ id = $ data ->{Schema::PROP_ID_D4 };
611609 $ refResolver = $ options ->refResolver ;
612610 $ parentScope = $ refResolver ->updateResolutionScope ($ id );
613611 /** @noinspection PhpUnusedLocalVariableInspection */
@@ -617,10 +615,10 @@ private function processObject($data, Context $options, $path, $result = null)
617615 }
618616
619617 if ($ import
620- && isset ($ data ->{self ::ID })
618+ && isset ($ data ->{self ::PROP_ID })
621619 && ($ options ->version >= Schema::VERSION_DRAFT_06 || $ options ->version === Schema::VERSION_AUTO )
622- && is_string ($ data ->{self ::ID }) /*&& (!isset($this->properties['id']))/* && $this->isMetaSchema($data)*/ ) {
623- $ id = $ data ->{self ::ID };
620+ && is_string ($ data ->{self ::PROP_ID }) ) {
621+ $ id = $ data ->{self ::PROP_ID };
624622 $ refResolver = $ options ->refResolver ;
625623 $ parentScope = $ refResolver ->updateResolutionScope ($ id );
626624 /** @noinspection PhpUnusedLocalVariableInspection */
@@ -632,11 +630,11 @@ private function processObject($data, Context $options, $path, $result = null)
632630 if ($ import ) {
633631 try {
634632 while (
635- isset ($ data ->{self ::REF })
636- && is_string ($ data ->{self ::REF })
637- && !isset ($ this ->properties [self ::REF ])
633+ isset ($ data ->{self ::PROP_REF })
634+ && is_string ($ data ->{self ::PROP_REF })
635+ && !isset ($ this ->properties [self ::PROP_REF ])
638636 ) {
639- $ refString = $ data ->{self ::REF };
637+ $ refString = $ data ->{self ::PROP_REF };
640638
641639 // todo check performance impact
642640 if ($ refString === 'http://json-schema.org/draft-04/schema# '
@@ -655,7 +653,6 @@ private function processObject($data, Context $options, $path, $result = null)
655653
656654 $ ref = $ refResolver ->resolveReference ($ refString );
657655 $ data = self ::unboolSchemaData ($ ref ->getData ());
658- //$data = $ref->getData();
659656 if (!$ options ->validateOnly ) {
660657 if ($ ref ->isImported ()) {
661658 $ refResult = $ ref ->getImported ();
@@ -728,7 +725,6 @@ private function processObject($data, Context $options, $path, $result = null)
728725 && !$ options ->validateOnly
729726 && $ options ->applyDefaults
730727 && $ properties !== null
731- && $ this ->objectItemClass !== 'Swaggest\JsonSchema\Schema ' // todo replace literal
732728 ) {
733729 foreach ($ properties as $ key => $ property ) {
734730 if (isset ($ property ->default )) {
@@ -777,7 +773,7 @@ private function processObject($data, Context $options, $path, $result = null)
777773 if ($ prop instanceof Schema) {
778774 $ value = $ prop ->process (
779775 $ value ,
780- isset ($ defaultApplied [$ key ]) ? $ options ->withSkipValidation () : $ options ,
776+ isset ($ defaultApplied [$ key ]) ? $ options ->withDefault () : $ options ,
781777 $ path . '->properties: ' . $ key
782778 );
783779 }
@@ -959,7 +955,7 @@ private function processContent($data, Context $options, $path)
959955 * @param mixed $data
960956 * @param Context $options
961957 * @param string $path
962- * @param null $result
958+ * @param mixed| null $result
963959 * @return array|mixed|null|object|\stdClass
964960 * @throws InvalidValue
965961 * @throws \Exception
@@ -969,20 +965,17 @@ public function process($data, Context $options, $path = '#', $result = null)
969965 {
970966
971967 $ import = $ options ->import ;
972- //$pathTrace = explode('->', $path);
973968
974969 if (!$ import && $ data instanceof ObjectItemContract) {
975970 $ result = new \stdClass ();
976971 if ($ options ->circularReferences ->contains ($ data )) {
977972 /** @noinspection PhpIllegalArrayKeyTypeInspection */
978973 $ path = $ options ->circularReferences [$ data ];
979974 // @todo $path is not a valid json pointer $ref
980- $ result ->{self ::REF } = $ path ;
975+ $ result ->{self ::PROP_REF } = $ path ;
981976 return $ result ;
982- // return $options->circularReferences[$data];
983977 }
984978 $ options ->circularReferences ->attach ($ data , $ path );
985- //$options->circularReferences->attach($data, $result);
986979
987980 $ data = $ data ->jsonSerialize ();
988981 }
0 commit comments