@@ -47,9 +47,6 @@ class PropertySchema
4747 /**@var \cebe\yii2openapi\lib\openapi\ComponentSchema $refSchema * */
4848 private $ refSchema ;
4949
50- /**@var string|null **/
51- private $ targetProperty = null ;
52-
5350 /**
5451 * @var bool
5552 */
@@ -64,6 +61,7 @@ class PropertySchema
6461 * @param \cebe\openapi\SpecObjectInterface $property
6562 * @param string $name
6663 * @param \cebe\yii2openapi\lib\openapi\ComponentSchema $schema
64+ * @throws \cebe\yii2openapi\lib\exceptions\InvalidDefinitionException
6765 * @throws \yii\base\InvalidConfigException
6866 */
6967 public function __construct (SpecObjectInterface $ property , string $ name , ComponentSchema $ schema )
@@ -92,17 +90,9 @@ private function initReference():void
9290 {
9391 $ this ->isReference = true ;
9492 $ this ->refPointer = $ this ->property ->getJsonReference ()->getJsonPointer ()->getPointer ();
95- $ refSchemaName = \str_replace ( self :: REFERENCE_PATH , '' , $ this ->refPointer );
93+ $ refSchemaName = $ this ->getRefSchemaName ( );
9694 if ($ this ->isRefPointerToSelf ()) {
9795 $ this ->refSchema = $ this ->schema ;
98- }elseif ($ this ->isRefPointerToProperty ()) {
99- $ this ->property ->getContext ()->mode = ReferenceContext::RESOLVE_MODE_INLINE ;
100- $ pattern = '~^ ' .self ::REFERENCE_PATH .'(?<schemaName>.+)/properties/(?<propName>.+)$~ ' ;
101- if (!\preg_match ($ pattern , $ this ->refPointer , $ matches )) {
102- throw new InvalidDefinitionException ('Invalid schema reference ' );
103- }
104- $ this ->targetProperty = $ matches ['propName ' ];
105- $ this ->refSchema = Yii::createObject (ComponentSchema::class, [$ this ->property ->resolve (), $ matches ['schemaName ' ]]);
10696 } elseif ($ this ->isRefPointerToSchema ()) {
10797 $ this ->property ->getContext ()->mode = ReferenceContext::RESOLVE_MODE_ALL ;
10898 $ this ->refSchema = Yii::createObject (ComponentSchema::class, [$ this ->property ->resolve (), $ refSchemaName ]);
@@ -123,18 +113,9 @@ private function initItemsReference():void
123113 $ this ->refPointer = $ items ->getJsonReference ()->getJsonPointer ()->getPointer ();
124114 if ($ this ->isRefPointerToSelf ()) {
125115 $ this ->refSchema = $ this ->schema ;
126- } elseif ($ this ->isRefPointerToProperty ()) {
127- $ items ->getContext ()->mode = ReferenceContext::RESOLVE_MODE_ALL ;
128- $ pattern = '~^ ' .self ::REFERENCE_PATH .'(?<schemaName>.+)/properties/(?<propName>.+)$~ ' ;
129- if (!\preg_match ($ pattern , $ this ->refPointer , $ matches )) {
130- throw new InvalidDefinitionException ('Invalid schema reference ' );
131- }
132- $ this ->targetProperty = $ matches ['propName ' ];
133- $ this ->refSchema = Yii::createObject (ComponentSchema::class, [$ items ->resolve (), $ matches ['schemaName ' ]]);
134116 } elseif ($ this ->isRefPointerToSchema ()) {
135117 $ items ->getContext ()->mode = ReferenceContext::RESOLVE_MODE_ALL ;
136- $ schemaName = \str_replace (self ::REFERENCE_PATH , '' , $ this ->refPointer );
137- $ this ->refSchema = Yii::createObject (ComponentSchema::class, [$ items ->resolve (), $ schemaName ]);
118+ $ this ->refSchema = Yii::createObject (ComponentSchema::class, [$ items ->resolve (), $ this ->getRefSchemaName ()]);
138119 }
139120 }
140121
@@ -176,17 +157,9 @@ public function getRefSchema():ComponentSchema
176157 */
177158 public function getTargetProperty ():?PropertySchema
178159 {
179- if ($ this ->targetProperty !== null && $ this ->isRefPointerToProperty ()) {
180- return $ this ->getRefSchema ()->getProperty ($ this ->targetProperty );
181- }
182160 return $ this ->getRefSchema ()->getProperty ($ this ->getRefSchema ()->getPkName ());
183161 }
184162
185- public function getTargetPropertyName ():?string
186- {
187- return $ this ->targetProperty ;
188- }
189-
190163 /**
191164 * @throws \yii\base\InvalidConfigException
192165 */
@@ -215,13 +188,6 @@ public function isRefPointerToSelf():bool
215188 && strpos ($ this ->refPointer , '/properties/ ' ) !== false ;
216189 }
217190
218- public function isRefPointerToProperty ():bool
219- {
220- return $ this ->isRefPointerToSchema ()
221- && strpos ($ this ->refPointer , '/ ' . $ this ->schema ->getName () . '/ ' ) === false
222- && strpos ($ this ->refPointer , '/properties/ ' ) !== false ;
223- }
224-
225191 public function getRefSchemaName ():string
226192 {
227193 if (!$ this ->isReference && !$ this ->isItemsReference ) {
0 commit comments