Skip to content

Commit

Permalink
PNP-14154 Added @deprecated into doc block of generated models/methods (
Browse files Browse the repository at this point in the history
  • Loading branch information
supersmile2009 authored and Webonaute committed Oct 10, 2017
1 parent cb951a5 commit a65ffa3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Extraction/Extractor/JmsExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,27 @@ public function extract($reflectionClass, $schema, ExtractionContextInterface $e

$propertySchema->serializerGroups = $item->groups;

/** @var \ReflectionProperty $reflectionProperty */
$reflectionProperty = $item->reflection;
// Reflecion can be null when extracting VirtualProperty
if ($reflectionProperty !== null) {
$docComment = $reflectionProperty->getDocComment();
// Can be false if there is no doc block
if ($docComment !== false) {
$factory = DocBlockFactory::createInstance();
$docBlock = $factory->create($reflectionProperty->getDocComment());
$deprecatedTags = $docBlock->getTagsByName('deprecated');
if (empty($deprecatedTags) === false) {
$propertySchema->deprecated = true;
/** @var \phpDocumentor\Reflection\DocBlock\Tags\Deprecated $deprecatedTag */
foreach ($deprecatedTags as $deprecatedTag) {
$propertySchema->deprecationDescription .= $deprecatedTag->getDescription();
}
}
}
}


$name = $this->namingStrategy->translateName($item);
$schema->properties[$name] = $propertySchema;

Expand Down
7 changes: 6 additions & 1 deletion Extraction/Extractor/PhpDocOperationExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,13 @@ public function extract($method, $operation, ExtractionContextInterface $extract
}
}

if ($docBlock->getTagsByName('deprecated')) {
$deprecatedTags = $docBlock->getTagsByName('deprecated');
if (empty($deprecatedTags) === false) {
$operation->deprecated = true;
/** @var \phpDocumentor\Reflection\DocBlock\Tags\Deprecated $deprecatedTag */
foreach ($deprecatedTags as $deprecatedTag) {
$operation->deprecationDescription .= $deprecatedTag->getDescription();
}
}

$bodyParameter = null;
Expand Down
10 changes: 10 additions & 0 deletions Schema/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ class Operation implements \ArrayAccess
*/
public $deprecated;

/**
* Deprecation description
*
* @var boolean
*
* @JMS\Type("string")
* @JMS\Exclude(if="object.deprecated !== true")
*/
public $deprecationDescription;

/**
* A declaration of which security schemes are applied for this operation.
* The list of values describes alternative security schemes that can be used
Expand Down
21 changes: 21 additions & 0 deletions Schema/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,27 @@ class Schema implements \ArrayAccess
*/
public $parentAlias;

/**
* Declares this item to be deprecated.
* Usage of the declared operation should be refrained.
*
* @var boolean
*
* @JMS\Type("boolean")
* @JMS\Exclude(if="object.ref !== null")
*/
public $deprecated = false;

/**
* Description of deprecation
*
* @var boolean
*
* @JMS\Type("string")
* @JMS\Exclude(if="object.ref !== null || object.deprecated !== true")
*/
public $deprecationDescription;

/**
* @JMS\PreSerialize()
*/
Expand Down

0 comments on commit a65ffa3

Please sign in to comment.