77
88namespace cebe \yii2openapi \lib \openapi ;
99
10+ use cebe \openapi \exceptions \UnresolvableReferenceException ;
1011use cebe \openapi \spec \MediaType ;
1112use cebe \openapi \spec \Operation ;
1213use cebe \openapi \spec \Reference ;
@@ -36,10 +37,10 @@ protected static function isObjectSchema($schema): bool
3637 protected static function isArraySchemaWithRefItems ($ schema ): bool
3738 {
3839 return isset ($ schema ->items ) && $ schema ->items instanceof Reference &&
39- (isset ($ schema ->type ) && $ schema ->type === 'array ' );
40+ (isset ($ schema ->type ) && $ schema ->type === 'array ' );
4041 }
4142
42- protected static function hasAttributesReference ($ schema ):bool
43+ protected static function hasAttributesReference ($ schema ): bool
4344 {
4445 return isset ($ schema ->properties ['attributes ' ]) && $ schema ->properties ['attributes ' ] instanceof Reference;
4546 }
@@ -58,11 +59,11 @@ protected static function schemaNameByRef($schemaOrReference): ?string
5859 }
5960
6061 /**
61- * @param \cebe\openapi\spec\ Operation $operation
62+ * @param Operation $operation
6263 * @return array
63- * @throws \cebe\openapi\exceptions\ UnresolvableReferenceException
64+ * @throws UnresolvableReferenceException
6465 */
65- public static function guessResponseRelations (Operation $ operation ):array
66+ public static function guessResponseRelations (Operation $ operation ): array
6667 {
6768 if (!isset ($ operation ->responses )) {
6869 return [];
@@ -112,12 +113,12 @@ public static function guessResponseRelations(Operation $operation):array
112113 }
113114
114115 /**
115- * @param \cebe\openapi\spec\ Operation $operation
116+ * @param Operation $operation
116117 * @param $actionType
117118 * @return string|null
118- * @throws \cebe\openapi\exceptions\ UnresolvableReferenceException
119+ * @throws UnresolvableReferenceException
119120 */
120- public static function guessModelClass (Operation $ operation , $ actionType ):?string
121+ public static function guessModelClass (Operation $ operation , $ actionType ): ?string
121122 {
122123 // first, check request body
123124 $ requestBody = $ operation ->requestBody ;
@@ -162,20 +163,26 @@ public static function guessModelClass(Operation $operation, $actionType):?strin
162163 }
163164
164165 /**
165- * @param \cebe\openapi\ SpecObjectInterface $property
166+ * @param SpecObjectInterface $property
166167 * @return array|null[]
167- * @throws \cebe\openapi\exceptions\ UnresolvableReferenceException
168+ * @throws UnresolvableReferenceException
168169 */
169170 public static function guessModelClassFromJsonResource (SpecObjectInterface $ property ): array
170171 {
171- $ schema = $ property instanceof Reference? $ property ->resolve () : $ property ;
172-
173- if (self ::isObjectSchema ($ schema ) && self ::hasAttributesReference ($ schema )) {
174- $ name = self ::schemaNameByRef ($ schema ->properties ['attributes ' ]);
175- if ($ name !== null ) {
176- return [$ name , '' , '' , 'object ' ];
172+ $ schema = $ property instanceof Reference ? $ property ->resolve () : $ property ;
173+ if (self ::isObjectSchema ($ schema )) {
174+ if (self ::hasAttributesReference ($ schema )) {
175+ $ name = self ::schemaNameByRef ($ schema ->properties ['attributes ' ]);
176+ if ($ name !== null ) {
177+ return [$ name , '' , '' , 'object ' ];
178+ }
179+ return [null , null , null , null ];
180+ } else { # https://github.com/cebe/yii2-openapi/issues/172
181+ $ name = self ::schemaNameByRef ($ property );
182+ if ($ name !== null ) {
183+ return [$ name , '' , '' , 'object ' ];
184+ }
177185 }
178- return [null , null , null , null ];
179186 }
180187 if (self ::isArraySchemaWithRefItems ($ property )) {
181188 $ ref = $ property ->items ->resolve ();
@@ -191,11 +198,11 @@ public static function guessModelClassFromJsonResource(SpecObjectInterface $prop
191198 }
192199
193200 /**
194- * @param \cebe\openapi\spec\ MediaType $content
201+ * @param MediaType $content
195202 * @return array|null[]
196- * @throws \cebe\openapi\exceptions\ UnresolvableReferenceException
203+ * @throws UnresolvableReferenceException
197204 */
198- public static function guessModelClassFromContent (MediaType $ content ):array
205+ public static function guessModelClassFromContent (MediaType $ content ): array
199206 {
200207 /** @var $referencedSchema Schema */
201208 if ($ content ->schema instanceof Reference) {
@@ -258,9 +265,9 @@ public static function guessModelClassFromContent(MediaType $content):array
258265 * @param Operation $operation
259266 * @param $modelClass
260267 * @return null|array
261- * @throws \cebe\openapi\exceptions\ UnresolvableReferenceException
268+ * @throws UnresolvableReferenceException
262269 */
263- public static function findResponseWrapper (Operation $ operation , $ modelClass ):?array
270+ public static function findResponseWrapper (Operation $ operation , $ modelClass ): ?array
264271 {
265272 if (!isset ($ operation ->responses )) {
266273 return null ;
0 commit comments