Skip to content

Commit

Permalink
Updated OpenAPISpecWriter & Parameter classes to allow for the option…
Browse files Browse the repository at this point in the history
…al 'format' modifier field to be included in the output schema.
  • Loading branch information
ArclightHub committed Dec 17, 2021
1 parent 30ea2dc commit b577931
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions camel/Extraction/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
{
Expand Down
3 changes: 3 additions & 0 deletions camel/Output/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down
8 changes: 6 additions & 2 deletions src/Writing/OpenAPISpecWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
1 change: 1 addition & 0 deletions tests/GenerateDocumentationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit b577931

Please sign in to comment.