finished up, tests passing, fixed cs

This commit is contained in:
Evan Villemez 2012-08-27 13:25:03 -04:00
parent 2902ac3cbb
commit 504d5125f9
7 changed files with 46 additions and 13 deletions

View File

@ -27,7 +27,7 @@ class ApiDoc
* @var string * @var string
*/ */
private $input = null; private $input = null;
/** /**
* @var string * @var string
*/ */
@ -67,7 +67,7 @@ class ApiDoc
* @var array * @var array
*/ */
private $parameters = array(); private $parameters = array();
/** /**
* @var array * @var array
*/ */
@ -98,7 +98,7 @@ class ApiDoc
if (isset($data['description'])) { if (isset($data['description'])) {
$this->description = $data['description']; $this->description = $data['description'];
} }
if (isset($data['return'])) { if (isset($data['return'])) {
$this->return = $data['return']; $this->return = $data['return'];
} }
@ -203,7 +203,7 @@ class ApiDoc
{ {
$this->parameters = $parameters; $this->parameters = $parameters;
} }
/** /**
* Sets the responsed data as processed by the parsers - same format as parameters * Sets the responsed data as processed by the parsers - same format as parameters
* *
@ -213,7 +213,7 @@ class ApiDoc
{ {
$this->response = $response; $this->response = $response;
} }
/** /**
* @return array * @return array
*/ */
@ -267,7 +267,7 @@ class ApiDoc
if ($requirements = $this->requirements) { if ($requirements = $this->requirements) {
$data['requirements'] = $requirements; $data['requirements'] = $requirements;
} }
if ($response = $this->response) { if ($response = $this->response) {
$data['response'] = $response; $data['response'] = $response;
} }

View File

@ -247,14 +247,14 @@ class ApiDocExtractor
// return (populates 'response' for the formatters) // return (populates 'response' for the formatters)
if (null !== $return = $annotation->getReturn()) { if (null !== $return = $annotation->getReturn()) {
$response = array(); $response = array();
foreach ($this->parsers as $parser) { foreach ($this->parsers as $parser) {
if ($parser->supports($return)) { if ($parser->supports($return)) {
$response = $parser->parse($return); $response = $parser->parse($return);
break; break;
} }
} }
$annotation->setResponse($response); $annotation->setResponse($response);
} }

View File

@ -85,6 +85,22 @@ class MarkdownFormatter extends AbstractFormatter
} }
} }
if (isset($data['response'])) {
$markdown .= "#### Response ####\n\n";
foreach ($data['response'] as $name => $parameter) {
$markdown .= sprintf("%s:\n\n", $name);
$markdown .= sprintf(" * type: %s\n", $parameter['dataType']);
$markdown .= sprintf(" * required: %s\n", $parameter['required'] ? 'true' : 'false');
if (isset($parameter['description']) && !empty($parameter['description'])) {
$markdown .= sprintf(" * description: %s\n", $parameter['description']);
}
$markdown .= "\n";
}
}
return $markdown; return $markdown;
} }

View File

@ -35,10 +35,10 @@ class JmsMetadataParser implements ParserInterface
try { try {
if ($meta = $this->factory->getMetadataForClass($input)) { if ($meta = $this->factory->getMetadataForClass($input)) {
return true; return true;
} }
} catch (\ReflectionException $e) { } catch (\ReflectionException $e) {
} }
return false; return false;
} }
@ -81,7 +81,6 @@ class JmsMetadataParser implements ParserInterface
//TODO: regex comment to get description - or move doc comment parsing functionality from `ApiDocExtractor` to a new location //TODO: regex comment to get description - or move doc comment parsing functionality from `ApiDocExtractor` to a new location
//in order to reuse it here //in order to reuse it here
return $description; return $description;
} }

View File

@ -104,7 +104,7 @@ class TestController
/** /**
* @ApiDoc( * @ApiDoc(
* description="Testing return", * description="Testing return",
* return="test_type" * return="dependency_type"
* ) * )
*/ */
public function jmsReturnTestAction() public function jmsReturnTestAction()

View File

@ -186,6 +186,19 @@ arr:
* description: No description. * description: No description.
### `GET` /jms-return-test ###
_Testing return_
#### Response ####
a:
* type: string
* required: true
* description: A nice description
### `ANY` /my-commented/{id}/{page} ### ### `ANY` /my-commented/{id}/{page} ###
_This method is useful to test if the getDocComment works._ _This method is useful to test if the getDocComment works._

View File

@ -220,7 +220,12 @@ class SimpleFormatterTest extends WebTestCase
'uri' => '/jms-return-test', 'uri' => '/jms-return-test',
'description' => 'Testing return', 'description' => 'Testing return',
'response' => array( 'response' => array(
'a' => array(
'dataType' => 'string',
'required' => true,
'description' => 'A nice description',
'readonly' => false
)
) )
), ),
5 => 5 =>