Skip to content

Commit

Permalink
[update] nullable Parameter For OpenApi3
Browse files Browse the repository at this point in the history
  • Loading branch information
liverocaisson committed Oct 2, 2023
1 parent e45e3af commit 31ee4ac
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Writing/OpenAPISpecWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,11 @@ public function generateFieldData($field): array
$field = new Parameter($field);
}

$fieldData = [];

if ($field->type === 'file') {
// See https://swagger.io/docs/specification/describing-request-body/file-upload/
return [
$fieldData = [
'type' => 'string',
'format' => 'binary',
'description' => $field->description ?: '',
Expand Down Expand Up @@ -498,10 +500,8 @@ public function generateFieldData($field): array
}
}
}

return $fieldData;
} else if ($field->type === 'object') {
return [
$fieldData = [
'type' => 'object',
'description' => $field->description ?: '',
'example' => $field->example,
Expand All @@ -510,17 +510,20 @@ public function generateFieldData($field): array
})->all()),
];
} else {
$schema = [
$fieldData = [
'type' => static::normalizeTypeName($field->type),
'description' => $field->description ?: '',
'example' => $field->example,
];
if (!empty($field->enumValues)) {
$schema['enum'] = $field->enumValues;
$fieldData['enum'] = $field->enumValues;
}
}

return $schema;
if (isset($field['required']) && !$field['required']) {
$fieldData['nullable'] = true;
}
return $fieldData;
}

protected function operationId(OutputEndpointData $endpoint): string
Expand Down

0 comments on commit 31ee4ac

Please sign in to comment.