2929 * Class Schema
3030 * @package Swaggest\JsonSchema
3131 */
32- class Schema extends JsonSchema implements MetaHolder
32+ class Schema extends JsonSchema implements MetaHolder, SchemaContract
3333{
3434 const CONST_PROPERTY = 'const ' ;
3535
@@ -95,7 +95,7 @@ public function addPropertyMapping($dataName, $propertyName, $mapping = self::DE
9595 /**
9696 * @param mixed $data
9797 * @param Context|null $options
98- * @return static|JsonSchema
98+ * @return SchemaContract
9999 * @throws Exception
100100 * @throws InvalidValue
101101 * @throws \Exception
@@ -124,7 +124,7 @@ public static function import($data, Context $options = null)
124124 }
125125
126126 $ data = self ::unboolSchema ($ data );
127- if ($ data instanceof Schema ) {
127+ if ($ data instanceof SchemaContract ) {
128128 return $ data ;
129129 }
130130
@@ -727,13 +727,14 @@ private function processObject($data, Context $options, $path, $result = null)
727727 && $ properties !== null
728728 ) {
729729 foreach ($ properties as $ key => $ property ) {
730- if (isset ($ property ->default )) {
730+ // todo check when property is \stdClass `{}` here (RefTest)
731+ if ($ property instanceof SchemaContract && null !== $ default = $ property ->getDefault ()) {
731732 if (isset ($ this ->__dataToProperty [$ options ->mapping ][$ key ])) {
732733 $ key = $ this ->__dataToProperty [$ options ->mapping ][$ key ];
733734 }
734735 if (!array_key_exists ($ key , $ array )) {
735736 $ defaultApplied [$ key ] = true ;
736- $ array [$ key ] = $ property -> default ;
737+ $ array [$ key ] = $ default ;
737738 }
738739 }
739740 }
@@ -751,7 +752,7 @@ private function processObject($data, Context $options, $path, $result = null)
751752 if (isset ($ deps ->$ key )) {
752753 $ dependencies = $ deps ->$ key ;
753754 $ dependencies = self ::unboolSchema ($ dependencies );
754- if ($ dependencies instanceof Schema ) {
755+ if ($ dependencies instanceof SchemaContract ) {
755756 $ dependencies ->process ($ data , $ options , $ path . '->dependencies: ' . $ key );
756757 } else {
757758 foreach ($ dependencies as $ item ) {
@@ -770,7 +771,7 @@ private function processObject($data, Context $options, $path, $result = null)
770771 $ prop = self ::unboolSchema ($ properties [$ key ]);
771772 $ propertyFound = true ;
772773 $ found = true ;
773- if ($ prop instanceof Schema ) {
774+ if ($ prop instanceof SchemaContract ) {
774775 $ value = $ prop ->process (
775776 $ value ,
776777 isset ($ defaultApplied [$ key ]) ? $ options ->withDefault () : $ options ,
@@ -806,7 +807,7 @@ private function processObject($data, Context $options, $path, $result = null)
806807 $ this ->fail (new ObjectException ('Additional properties not allowed ' ), $ path . ': ' . $ key );
807808 }
808809
809- if ($ this ->additionalProperties instanceof Schema ) {
810+ if ($ this ->additionalProperties instanceof SchemaContract ) {
810811 $ value = $ this ->additionalProperties ->process ($ value , $ options , $ path . '->additionalProperties: ' . $ key );
811812 }
812813
@@ -863,7 +864,7 @@ private function processArray($data, Context $options, $path, $result)
863864
864865 $ pathItems = 'items ' ;
865866 $ this ->items = self ::unboolSchema ($ this ->items );
866- if ($ this ->items instanceof Schema ) {
867+ if ($ this ->items instanceof SchemaContract ) {
867868 $ items = array ();
868869 $ additionalItems = $ this ->items ;
869870 } elseif ($ this ->items === null ) { // items defaults to empty schema so everything is valid
@@ -886,7 +887,7 @@ private function processArray($data, Context $options, $path, $result)
886887 $ itemSchema = self ::unboolSchema ($ items [$ index ]);
887888 $ result [$ key ] = $ itemSchema ->process ($ value , $ options , $ path . '->items: ' . $ index );
888889 } else {
889- if ($ additionalItems instanceof Schema ) {
890+ if ($ additionalItems instanceof SchemaContract ) {
890891 $ result [$ key ] = $ additionalItems ->process ($ value , $ options , $ path . '-> ' . $ pathItems
891892 . '[ ' . $ index . '] ' );
892893 } elseif (!$ options ->skipValidation && $ additionalItems === false ) {
@@ -1235,4 +1236,18 @@ private static function unboolSchemaData($data)
12351236 }
12361237 }
12371238
1239+ public function getDefault ()
1240+ {
1241+ return $ this ->default ;
1242+ }
1243+
1244+ public function getProperties ()
1245+ {
1246+ return $ this ->properties ;
1247+ }
1248+
1249+ public function getObjectItemClass ()
1250+ {
1251+ return $ this ->objectItemClass ;
1252+ }
12381253}
0 commit comments