@@ -76,10 +76,19 @@ class AttributeResolver
76
76
/** @var Config */
77
77
private $ config ;
78
78
79
- public function __construct (string $ schemaName , ComponentSchema $ schema , JunctionSchemas $ junctions , ?Config $ config = null )
79
+ public $ resolvedComponentSchema ;
80
+
81
+ public function __construct (
82
+ string $ schemaName ,
83
+ ComponentSchema $ schema ,
84
+ JunctionSchemas $ junctions ,
85
+ ?Config $ config = null ,
86
+ $ resolvedComponentSchema = null
87
+ )
80
88
{
81
89
$ this ->schemaName = $ schemaName ;
82
90
$ this ->componentSchema = $ schema ;
91
+ $ this ->resolvedComponentSchema = $ resolvedComponentSchema ;
83
92
$ this ->tableName = $ schema ->resolveTableName ($ schemaName );
84
93
$ this ->junctions = $ junctions ;
85
94
$ this ->isJunctionSchema = $ junctions ->isJunctionSchema ($ schemaName );
@@ -94,9 +103,18 @@ public function __construct(string $schemaName, ComponentSchema $schema, Junctio
94
103
*/
95
104
public function resolve ():DbModel
96
105
{
97
- foreach ($ this ->componentSchema ->getProperties () as $ property ) {
106
+ foreach ($ this ->componentSchema ->getProperties () as $ key => $ property ) {
98
107
/** @var $property \cebe\yii2openapi\lib\openapi\PropertySchema */
99
108
109
+ $ resolvedProperty = null ;
110
+ if ($ this ->resolvedComponentSchema ) {
111
+ foreach ($ this ->resolvedComponentSchema ->getProperties () as $ key2 => $ prop ) {
112
+ if ($ key === $ key2 ) {
113
+ $ resolvedProperty = $ prop ;
114
+ }
115
+ }
116
+ }
117
+
100
118
$ isRequired = $ this ->componentSchema ->isRequiredProperty ($ property ->getName ());
101
119
$ nullableValue = $ property ->getProperty ()->getSerializableData ()->nullable ?? null ;
102
120
if ($ nullableValue === false ) { // see docs in README regarding NOT NULL, required and nullable
@@ -106,9 +124,9 @@ public function resolve():DbModel
106
124
if ($ this ->isJunctionSchema ) {
107
125
$ this ->resolveJunctionTableProperty ($ property , $ isRequired );
108
126
} elseif ($ this ->hasMany2Many ) {
109
- $ this ->resolveHasMany2ManyTableProperty ($ property , $ isRequired );
127
+ $ this ->resolveHasMany2ManyTableProperty ($ property , $ isRequired, $ resolvedProperty );
110
128
} else {
111
- $ this ->resolveProperty ($ property , $ isRequired , $ nullableValue );
129
+ $ this ->resolveProperty ($ property , $ isRequired , $ nullableValue, $ resolvedProperty );
112
130
}
113
131
}
114
132
return Yii::createObject (DbModel::class, [
@@ -169,7 +187,7 @@ protected function resolveJunctionTableProperty(PropertySchema $property, bool $
169
187
* @throws \cebe\yii2openapi\lib\exceptions\InvalidDefinitionException
170
188
* @throws \yii\base\InvalidConfigException
171
189
*/
172
- protected function resolveHasMany2ManyTableProperty (PropertySchema $ property , bool $ isRequired ):void
190
+ protected function resolveHasMany2ManyTableProperty (PropertySchema $ property , bool $ isRequired, $ resolvedProperty = null ):void
173
191
{
174
192
if ($ this ->junctions ->isManyToManyProperty ($ this ->schemaName , $ property ->getName ())) {
175
193
return ;
@@ -203,7 +221,7 @@ protected function resolveHasMany2ManyTableProperty(PropertySchema $property, bo
203
221
return ;
204
222
}
205
223
206
- $ this ->resolveProperty ($ property , $ isRequired );
224
+ $ this ->resolveProperty ($ property , $ isRequired, $ resolvedProperty );
207
225
}
208
226
209
227
/**
@@ -216,14 +234,15 @@ protected function resolveHasMany2ManyTableProperty(PropertySchema $property, bo
216
234
protected function resolveProperty (
217
235
PropertySchema $ property ,
218
236
bool $ isRequired ,
219
- $ nullableValue = 'ARG_ABSENT '
237
+ $ nullableValue = 'ARG_ABSENT ' ,
238
+ $ resolvedProperty = null
220
239
):void {
221
240
if ($ nullableValue === 'ARG_ABSENT ' ) {
222
241
$ nullableValue = $ property ->getProperty ()->getSerializableData ()->nullable ?? null ;
223
242
}
224
243
$ attribute = Yii::createObject (Attribute::class, [$ property ->getName ()]);
225
244
$ attribute ->setRequired ($ isRequired )
226
- ->setDescription ($ property ->getAttr ('description ' , '' ))
245
+ ->setDescription ($ resolvedProperty ? $ resolvedProperty -> getAttr ( ' description ' , '' ) : $ property ->getAttr ('description ' , '' ))
227
246
->setReadOnly ($ property ->isReadonly ())
228
247
->setDefault ($ property ->guessDefault ())
229
248
->setXDbType ($ property ->getAttr (CustomSpecAttr::DB_TYPE ))
@@ -262,7 +281,7 @@ protected function resolveProperty(
262
281
$ attribute ->setPhpType ($ fkProperty ->guessPhpType ())
263
282
->setDbType ($ fkProperty ->guessDbType (true ))
264
283
->setSize ($ fkProperty ->getMaxLength ())
265
- ->setDescription ($ property ->getRefSchema ()->getDescription ())
284
+ ->setDescription ($ resolvedProperty ? $ resolvedProperty -> getAttr ( ' description ' , '' ) : $ property ->getRefSchema ()->getDescription ())
266
285
->setDefault ($ fkProperty ->guessDefault ())
267
286
->setLimits ($ min , $ max , $ fkProperty ->getMinLength ());
268
287
0 commit comments