Skip to content

Commit a2cb7a5

Browse files
committed
Improved array parameter and default value formatting
1 parent 80a1575 commit a2cb7a5

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

Annotations/AnnotationGenerator.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ protected function buildParameterAnnotation(string $paramName, array $paramMetad
206206
$docType = strtolower(trim($paramDocInfo['type'] ?? ''));
207207
$metaType = strtolower(trim($paramMetadata['type'] ?? $docType));
208208
$type = $metaType === 'string' && $docType !== 'string' ? $docType : $metaType;
209+
// If the signature type is array, but the type hinting provides more, use that instead
210+
if ($type === 'array' && strpos($docType, '[]') !== false && strpos($docType, '|') === false) {
211+
$type = $docType;
212+
}
209213
$typesMap = [];
210214
// Check for pipes and try to list possible types
211215
foreach (explode('|', $type) as $typePart) {
@@ -520,7 +524,12 @@ protected function buildSchemaObjectArray(string $type, string $subType = '', st
520524
}
521525

522526
if ($this->shouldIncludeDefault($type, $default)) {
523-
$schemaMap[] = 'default="' . $default . '"';
527+
$doubleQuote = '"';
528+
// Don't wrap with quotes for certain values
529+
if (in_array($default, ['{}', "{$doubleQuote}{$doubleQuote}"])) {
530+
$doubleQuote = '';
531+
}
532+
$schemaMap[] = "default={$doubleQuote}{$default}{$doubleQuote}";
524533
}
525534

526535
return ['@OA\Schema' => $schemaMap];

0 commit comments

Comments
 (0)