diff --git a/camel/Extraction/Parameter.php b/camel/Extraction/Parameter.php index ed8d4311..182e3aba 100644 --- a/camel/Extraction/Parameter.php +++ b/camel/Extraction/Parameter.php @@ -12,6 +12,7 @@ class Parameter extends BaseDTO public bool $required = false; public $example = null; public string $type = 'string'; + public ?string $format = null; public function __construct(array $parameters = []) { diff --git a/camel/Output/Parameter.php b/camel/Output/Parameter.php index 496837b4..4c382524 100644 --- a/camel/Output/Parameter.php +++ b/camel/Output/Parameter.php @@ -19,6 +19,9 @@ class Parameter extends \Knuckles\Camel\Extraction\Parameter /** @var string */ public string $type = 'string'; + /** @var string|null */ + public ?string $format = null; + /** @var array */ public $__fields = []; diff --git a/src/Writing/OpenAPISpecWriter.php b/src/Writing/OpenAPISpecWriter.php index 54592806..8ca5ebf1 100644 --- a/src/Writing/OpenAPISpecWriter.php +++ b/src/Writing/OpenAPISpecWriter.php @@ -541,11 +541,15 @@ public function generateFieldData($field): array })->all(), ]; } else { - return [ + $optionalSchema = []; + if (!is_null($field->format)) { + $optionalSchema['format'] = $field->format; + } + return array_merge([ 'type' => $this->normalizeTypeName($field->type), 'description' => $field->description ?: '', 'example' => $field->example, - ]; + ], $optionalSchema); } } } diff --git a/tests/GenerateDocumentationTest.php b/tests/GenerateDocumentationTest.php index d1ed736a..0ae494f4 100644 --- a/tests/GenerateDocumentationTest.php +++ b/tests/GenerateDocumentationTest.php @@ -336,6 +336,7 @@ public function will_not_overwrite_manually_modified_content_unless_force_flag_i 'required' => true, 'example' => 6, 'type' => 'integer', + 'format' => null, ]; $group['endpoints'][0]['urlParameters']['a_param'] = $extraParam; file_put_contents($group1FilePath, Yaml::dump(