Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions generate-spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,9 @@
if (!$queryParameter->type->nullable && !$queryParameter->type->hasDefaultValue) {
$parameter['required'] = true;
}
if ($queryParameter->type->deprecated) {
$parameter['deprecated'] = true;
}
$parameter['schema'] = $queryParameter->type->toArray(true);

$parameters[] = $parameter;
Expand Down
5 changes: 5 additions & 0 deletions src/ControllerMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ public static function parse(string $context,
continue;
}

if (str_contains($param->type->description, '@deprecated')) {
$param->type->deprecated = true;
$param->type->description = str_replace('@deprecated', 'Deprecated:', $param->type->description);
}

$parameters[] = $param;
}

Expand Down
9 changes: 7 additions & 2 deletions src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,13 @@ public static function cleanEmptyResponseArray(array $schema): array|stdClass {

public static function classMethodHasAnnotationOrAttribute(ClassMethod|Class_|Node $node, string $annotation): bool {
$doc = $node->getDocComment()?->getText();
if ($doc !== null && str_contains($doc, '@' . $annotation)) {
return true;

if ($doc !== null) {
if ($annotation !== 'deprecated' && str_contains($doc, '@' . $annotation)) {
return true;
} elseif ($annotation === 'deprecated' && str_contains($doc, '* @' . $annotation)) {
return true;
}
}

/** @var AttributeGroup $attrGroup */
Expand Down
4 changes: 4 additions & 0 deletions src/OpenApiType.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function __construct(
public ?string $format = null,
public bool $nullable = false,
public bool $hasDefaultValue = false,
public bool $deprecated = false,
public mixed $defaultValue = null,
public ?OpenApiType $items = null,
public ?array $properties = null,
Expand Down Expand Up @@ -98,6 +99,9 @@ enum: [0, 1],
if ($this->nullable) {
$values['nullable'] = true;
}
if ($this->deprecated) {
$values['deprecated'] = true;
}
if ($this->hasDefaultValue && $this->defaultValue !== null) {
$values['default'] = $this->type === 'object' && empty($this->defaultValue) ? new stdClass() : $this->defaultValue;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,11 @@
['name' => 'Settings#withCorsAnnotation', 'url' => '/api/{apiVersion}/cors/annotation', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#withCorsAttribute', 'url' => '/api/{apiVersion}/cors/attribute', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#docsParsingStatuscode', 'url' => '/api/{apiVersion}/docs-parsing-status-code', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#deprecatedRoute', 'url' => '/api/{apiVersion}/deprecated', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#deprecatedRouteGet', 'url' => '/api/{apiVersion}/deprecated-get', 'verb' => 'GET', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#deprecatedParameter', 'url' => '/api/{apiVersion}/deprecated-parameter', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#deprecatedParameterGet', 'url' => '/api/{apiVersion}/deprecated-parameter-get', 'verb' => 'GET', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#deprecatedRouteAndParameter', 'url' => '/api/{apiVersion}/deprecated-route-parameter', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#deprecatedRouteAndParameterGet', 'url' => '/api/{apiVersion}/deprecated-route-parameter-get', 'verb' => 'GET', 'requirements' => ['apiVersion' => '(v2)']],
],
];
80 changes: 80 additions & 0 deletions tests/lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,4 +635,84 @@ public function withCorsAttribute(): DataResponse {
public function docsParsingStatuscode(string $param): DataResponse {
return new DataResponse();
}

/**
* A deprecated POST route
*
* @param bool $active Not deprecated
* @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
* @deprecated 1.0.0 Use {@see SettingsController::trueFalseParameter()} instead
*
* 200: Admin settings updated
*/
public function deprecatedRoute(bool $active): DataResponse {
return new DataResponse();
}

/**
* A deprecated GET route
*
* @param bool $active Not deprecated
* @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
* @deprecated 1.0.0 Use {@see SettingsController::trueFalseParameter()} instead
*
* 200: Admin settings updated
*/
public function deprecatedRouteGet(bool $active): DataResponse {
return new DataResponse();
}

/**
* A deprecated parameter does not deprecate the POST method
*
* @param bool $active Not deprecated
* @param bool $deprecated boolean @deprecated This parameter will be removed in a future version
* @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
*
* 200: Admin settings updated
*/
public function deprecatedParameter(bool $active, bool $deprecated): DataResponse {
return new DataResponse();
}

/**
* A deprecated parameter does not deprecate the GET method
*
* @param bool $active Not deprecated
* @param bool $deprecated boolean @deprecated This parameter will be removed in a future version
* @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
*
* 200: Admin settings updated
*/
public function deprecatedParameterGet(bool $active, bool $deprecated): DataResponse {
return new DataResponse();
}

/**
* A deprecated parameter on a deprecated POST method
*
* @param bool $active Not deprecated
* @param bool $deprecated boolean @deprecated This parameter will be removed in a future version
* @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
* @deprecated 1.0.0 Use {@see SettingsController::trueFalseParameter()} instead
*
* 200: Admin settings updated
*/
public function deprecatedRouteAndParameter(bool $active, bool $deprecated): DataResponse {
return new DataResponse();
}

/**
* A deprecated parameter on a deprecated GET method
*
* @param bool $active Not deprecated
* @param bool $deprecated boolean @deprecated This parameter will be removed in a future version
* @return DataResponse<Http::STATUS_OK, list<empty>, array{}>
* @deprecated 1.0.0 Use {@see SettingsController::trueFalseParameter()} instead
*
* 200: Admin settings updated
*/
public function deprecatedRouteAndParameterGet(bool $active, bool $deprecated): DataResponse {
return new DataResponse();
}
}
Loading
Loading