Skip to content

Commit ba6d597

Browse files
authored
Merge pull request #44 from php-api-clients/dont-apply-nullable-to-hydrator-annotations
Don't apply nullable to hydrator annotations
2 parents 1dfee86 + e72d209 commit ba6d597

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/Generator/Schema.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,30 +117,30 @@ public static function generate(string $name, string $namespace, string $classNa
117117
], $property->type);
118118

119119
if ($t !== '') {
120-
$propertyStmt->setType($nullable . $t);
121-
$method->setReturnType($nullable . $t);
120+
$propertyStmt->setType(($t === 'array' ? '' : $nullable) . $t);
121+
$method->setReturnType(($t === 'array' ? '' : $nullable) . $t);
122122
}
123123
}
124124
}
125125

126126
if (is_array($property->anyOf) && $property->anyOf[0] instanceof OpenAPiSchema && array_key_exists(spl_object_hash($property->anyOf[0]), $schemaClassNameMap)) {
127-
$fqcnn = $nullable . '\\' . $rootNamespace . '\\' . $schemaClassNameMap[spl_object_hash($property->anyOf[0])];
128-
$propertyStmt->setType($fqcnn);
129-
$method->setReturnType($fqcnn);
127+
$fqcnn = '\\' . $rootNamespace . '\\' . $schemaClassNameMap[spl_object_hash($property->anyOf[0])];
128+
$propertyStmt->setType($nullable . $fqcnn);
129+
$method->setReturnType($nullable . $fqcnn);
130130
$propertyDocBlock[] = '@\WyriHaximus\Hydrator\Attribute\Hydrate(' . $fqcnn . '::class)';
131131
$setDefaylt = false;
132132
} else if (is_array($property->allOf) && $property->allOf[0] instanceof OpenAPiSchema && array_key_exists(spl_object_hash($property->allOf[0]), $schemaClassNameMap)) {
133-
$fqcnn = $nullable . '\\' . $rootNamespace . '\\' . $schemaClassNameMap[spl_object_hash($property->allOf[0])];
134-
$propertyStmt->setType($fqcnn);
135-
$method->setReturnType($fqcnn);
133+
$fqcnn = '\\' . $rootNamespace . '\\' . $schemaClassNameMap[spl_object_hash($property->allOf[0])];
134+
$propertyStmt->setType($nullable . $fqcnn);
135+
$method->setReturnType($nullable . $fqcnn);
136136
$propertyDocBlock[] = '@\WyriHaximus\Hydrator\Attribute\Hydrate(' . $fqcnn . '::class)';
137137
$setDefaylt = false;
138138
}
139139

140140
if ($property->type === 'object' && $property instanceof OpenAPiSchema && array_key_exists(spl_object_hash($property), $schemaClassNameMap)) {
141-
$fqcnn = $nullable . '\\' . $rootNamespace . '\\' . $schemaClassNameMap[spl_object_hash($property)];
142-
$propertyStmt->setType($fqcnn);
143-
$method->setReturnType($fqcnn);
141+
$fqcnn = '\\' . $rootNamespace . '\\' . $schemaClassNameMap[spl_object_hash($property)];
142+
$propertyStmt->setType($nullable . $fqcnn);
143+
$method->setReturnType($nullable . $fqcnn);
144144
$propertyDocBlock[] = '@\WyriHaximus\Hydrator\Attribute\Hydrate(' . $fqcnn . '::class)';
145145
$setDefaylt = false;
146146
}

0 commit comments

Comments
 (0)