@@ -40,12 +40,12 @@ class Schema extends JsonSchema implements MetaHolder
40
40
const VERSION_DRAFT_06 = 6 ;
41
41
const VERSION_DRAFT_07 = 7 ;
42
42
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 ' ;
46
46
47
47
// Object
48
- /** @var Properties|Schema[]|Schema */
48
+ /** @var null| Properties|Schema[]|Schema */
49
49
public $ properties ;
50
50
/** @var Schema|bool */
51
51
public $ additionalProperties ;
@@ -106,7 +106,7 @@ public static function import($data, Context $options = null)
106
106
$ options = new Context ();
107
107
}
108
108
109
- // $options->applyDefaults = false; // todo check infinite recursion on items, additionalProperties, etc...
109
+ $ options ->applyDefaults = false ;
110
110
111
111
if (isset ($ options ->schemasCache ) && is_object ($ data )) {
112
112
if ($ options ->schemasCache ->contains ($ data )) {
@@ -120,7 +120,7 @@ public static function import($data, Context $options = null)
120
120
121
121
// string $data is expected to be $ref uri
122
122
if (is_string ($ data )) {
123
- $ data = (object )array (self ::REF => $ data );
123
+ $ data = (object )array (self ::PROP_REF => $ data );
124
124
}
125
125
126
126
$ data = self ::unboolSchema ($ data );
@@ -302,8 +302,7 @@ private function processString($data, $path)
302
302
if ($ this ->format !== null ) {
303
303
$ validationError = Format::validationError ($ this ->format , $ data );
304
304
if ($ validationError !== null ) {
305
- if ($ this ->format === "uri " && substr ($ path , -3 ) === ':id ' ) {
306
- } else {
305
+ if (!($ this ->format === "uri " && substr ($ path , -3 ) === ':id ' )) {
307
306
$ this ->fail (new StringException ($ validationError ), $ path );
308
307
}
309
308
}
@@ -564,7 +563,6 @@ private function processObject($data, Context $options, $path, $result = null)
564
563
if ($ this ->useObjectAsArray ) {
565
564
$ result = array ();
566
565
} elseif (!$ result instanceof ObjectItemContract) {
567
- //$result = $this->makeObjectItem($options);
568
566
//* todo check performance impact
569
567
if (null === $ this ->objectItemClass ) {
570
568
$ result = new ObjectItem ();
@@ -604,10 +602,10 @@ private function processObject($data, Context $options, $path, $result = null)
604
602
// @todo better check for schema id
605
603
606
604
if ($ import
607
- && isset ($ data ->{Schema::ID_D4 })
605
+ && isset ($ data ->{Schema::PROP_ID_D4 })
608
606
&& ($ 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 };
611
609
$ refResolver = $ options ->refResolver ;
612
610
$ parentScope = $ refResolver ->updateResolutionScope ($ id );
613
611
/** @noinspection PhpUnusedLocalVariableInspection */
@@ -617,10 +615,10 @@ private function processObject($data, Context $options, $path, $result = null)
617
615
}
618
616
619
617
if ($ import
620
- && isset ($ data ->{self ::ID })
618
+ && isset ($ data ->{self ::PROP_ID })
621
619
&& ($ 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 };
624
622
$ refResolver = $ options ->refResolver ;
625
623
$ parentScope = $ refResolver ->updateResolutionScope ($ id );
626
624
/** @noinspection PhpUnusedLocalVariableInspection */
@@ -632,11 +630,11 @@ private function processObject($data, Context $options, $path, $result = null)
632
630
if ($ import ) {
633
631
try {
634
632
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 ])
638
636
) {
639
- $ refString = $ data ->{self ::REF };
637
+ $ refString = $ data ->{self ::PROP_REF };
640
638
641
639
// todo check performance impact
642
640
if ($ refString === 'http://json-schema.org/draft-04/schema# '
@@ -655,7 +653,6 @@ private function processObject($data, Context $options, $path, $result = null)
655
653
656
654
$ ref = $ refResolver ->resolveReference ($ refString );
657
655
$ data = self ::unboolSchemaData ($ ref ->getData ());
658
- //$data = $ref->getData();
659
656
if (!$ options ->validateOnly ) {
660
657
if ($ ref ->isImported ()) {
661
658
$ refResult = $ ref ->getImported ();
@@ -728,7 +725,6 @@ private function processObject($data, Context $options, $path, $result = null)
728
725
&& !$ options ->validateOnly
729
726
&& $ options ->applyDefaults
730
727
&& $ properties !== null
731
- && $ this ->objectItemClass !== 'Swaggest\JsonSchema\Schema ' // todo replace literal
732
728
) {
733
729
foreach ($ properties as $ key => $ property ) {
734
730
if (isset ($ property ->default )) {
@@ -777,7 +773,7 @@ private function processObject($data, Context $options, $path, $result = null)
777
773
if ($ prop instanceof Schema) {
778
774
$ value = $ prop ->process (
779
775
$ value ,
780
- isset ($ defaultApplied [$ key ]) ? $ options ->withSkipValidation () : $ options ,
776
+ isset ($ defaultApplied [$ key ]) ? $ options ->withDefault () : $ options ,
781
777
$ path . '->properties: ' . $ key
782
778
);
783
779
}
@@ -959,7 +955,7 @@ private function processContent($data, Context $options, $path)
959
955
* @param mixed $data
960
956
* @param Context $options
961
957
* @param string $path
962
- * @param null $result
958
+ * @param mixed| null $result
963
959
* @return array|mixed|null|object|\stdClass
964
960
* @throws InvalidValue
965
961
* @throws \Exception
@@ -969,20 +965,17 @@ public function process($data, Context $options, $path = '#', $result = null)
969
965
{
970
966
971
967
$ import = $ options ->import ;
972
- //$pathTrace = explode('->', $path);
973
968
974
969
if (!$ import && $ data instanceof ObjectItemContract) {
975
970
$ result = new \stdClass ();
976
971
if ($ options ->circularReferences ->contains ($ data )) {
977
972
/** @noinspection PhpIllegalArrayKeyTypeInspection */
978
973
$ path = $ options ->circularReferences [$ data ];
979
974
// @todo $path is not a valid json pointer $ref
980
- $ result ->{self ::REF } = $ path ;
975
+ $ result ->{self ::PROP_REF } = $ path ;
981
976
return $ result ;
982
- // return $options->circularReferences[$data];
983
977
}
984
978
$ options ->circularReferences ->attach ($ data , $ path );
985
- //$options->circularReferences->attach($data, $result);
986
979
987
980
$ data = $ data ->jsonSerialize ();
988
981
}
0 commit comments