Skip to content

Commit

Permalink
Merge pull request #19 from Gaus57/master
Browse files Browse the repository at this point in the history
Add @restdock-ignoreField and @restdock-ignoreExtraField tags
  • Loading branch information
pahanini authored Mar 22, 2017
2 parents 5242213 + 230a282 commit fd0d065
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ Use @restdoc-extraField and @restdoc-extraLink for extra fields.

Use @restdoc-sortField to sort field according to your code.

### Skip fields

Use @restdoc-ignore to skip field.

```php

/**
* @restdoc-ignore $hidden
*/
```

## Integrate With Slate

[Slate](https://github.com/tripit/slate) is probably one of the best tools to generate nice API. So you can
Expand Down
33 changes: 33 additions & 0 deletions models/ModelDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ private function _addField(&$fields, $name, $type = '', $description = '', $scen
$fields[$name]->setType($type);
}

/**
* @param array $fields
* @param string $name
*/
private function _removeField(&$fields, $name)
{
if (isset($fields[$name])) {
unset($fields[$name]);
}
}

/**
* @param string $name
* @param string $type
Expand All @@ -65,6 +76,22 @@ public function addExtraField($name, $type = '', $description = '')
$this->_addField($this->_extraFields, $name, $type, $description);
}

/**
* @param string $name
*/
public function removeField($name)
{
$this->_removeField($this->_fields, $name);
}

/**
* @param string $name
*/
public function removeExtraField($name)
{
$this->_removeField($this->_extraFields, $name);
}

/**
* @param $name
*/
Expand Down Expand Up @@ -263,6 +290,12 @@ public function prepare()
}
}

foreach ($this->getTagsByName('ignore') as $key => $tag) {
$name = trim($tag->getVariableName(), '$');
$this->removeField($name);
$this->removeExtraField($name);
}

foreach ($this->_fields as $field) {
$field->prepare();
}
Expand Down
1 change: 1 addition & 0 deletions models/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static function registerTagHandlers()
'label' => '\phpDocumentor\Reflection\DocBlock\Tag',
'extraField' => '\phpDocumentor\Reflection\DocBlock\Tag\ParamTag',
'extraLink' => '\phpDocumentor\Reflection\DocBlock\Tag\ParamTag',
'ignore' => '\phpDocumentor\Reflection\DocBlock\Tag\ParamTag',
];
foreach ($mapping as $suffix => $class) {
$tagName = Doc::TAG_PREFIX . $suffix;
Expand Down
4 changes: 4 additions & 0 deletions tests/models/NewSpecialOffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class NewSpecialOffer extends SpecialOffer
* @inheritdoc
*
* @restdoc-extraField string $alpha2 Code country. <a href="http://example.com">Detail link.</a>
* @restdoc-ignore $ignore
*/
public function extraFields()
{
Expand All @@ -23,6 +24,9 @@ public function extraFields()
},
'full_name' => function () {
return 'full_name';
},
'ignore' => function () {
return 'ignore';
}
];
}
Expand Down
6 changes: 4 additions & 2 deletions tests/models/SpecialOffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SpecialOffer extends Product
* @restdoc-link comment $text
* @restdoc-link $comment
* @restdoc-sortField $text
* @restdoc-ignore $is_ignore
*/
public function fields()
{
Expand All @@ -28,14 +29,15 @@ public function fields()
'title' => function () {
return 'title';
},
'text' => 'Comment'
'text' => 'Comment',
'is_ignore'
];
}

public function scenarios()
{
return [
'api-create' => ['id', 'title', 'note'],
'api-create' => ['id', 'title', 'note', 'is_ignore'],
'api-update' => ['comment'],
];
}
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/models/ModelParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ public function testInherit()
$this->assertEquals('Code country. <a href="http://example.com">Detail link.</a>', $doc->extraFields['alpha2']->description);
$this->assertEquals('string|null', $doc->extraFields['full_name']->type);
$this->assertEquals('Full name. <a href="http://example.com">Detail link.</a>', $doc->extraFields['full_name']->description);
$this->assertArrayNotHasKey('ignore', $doc->extraFields);

$this->assertEquals(5, count($doc->fields));
$this->assertEquals('int', $doc->fields['id']->type);
$this->assertEquals('string', $doc->fields['title']->type);
$this->assertEquals('string', $doc->fields['comment']->type);
$this->assertArrayNotHasKey('is_ignore', $doc->fields);

$this->assertEquals('string', $doc->fields['note']->type);
$this->assertEquals('string', $doc->fields['text']->type);
Expand Down

0 comments on commit fd0d065

Please sign in to comment.