Skip to content

Commit

Permalink
Some fixes for HandleReferences (for zircote#301 starts work as assume)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dezzpil committed Aug 14, 2017
1 parent 56b0d87 commit 5d333a5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Annotations/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ public function validate($parents = [], $skip = [], $ref = '')
$valid = parent::validate($parents, $skip);
if ($this->responses !== null) {
foreach ($this->responses as $response) {
if ($response->response !== 'default' && preg_match('/^[12345]{1}[0-9]{2}$/', $response->response) === 0) {
Logger::notice('Invalid value "' . $response->response . '" for ' . $response->_identity([]) . '->response, expecting "default" or a HTTP Status Code in ' . $response->_context);
if ($response->response !== 'default' && preg_match('/^[12345]{1}[0-9]{2}$/', $response->response) === 0 && (strpos($response->response, '$') === false)) {
Logger::notice('Invalid value "' . $response->response . '" for ' . $response->_identity([]) . '->response, expecting "default" or a HTTP Status Code or $linkName in ' . $response->_context);
}
}
}
Expand Down
19 changes: 13 additions & 6 deletions src/Processors/HandleReferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __invoke(Analysis $analysis)
{
$this->getAllImports($analysis);
$this->mapReferences();
$this->importReferences();
$this->importReferences($analysis);
}

/**
Expand Down Expand Up @@ -89,9 +89,10 @@ private function loadResponses(Operation $operation)
{
if (!is_null($operation->responses)) {
foreach ($operation->responses as $item) {
if ($this->checkSyntax($item->ref)) {
$this->references[$this->import_in_order['response']][] = $this->link($item);
}
// if ($this->checkSyntax($item->ref)) {
// $this->references[$this->import_in_order['response']][] = $this->link($item);
// }
$this->references[$this->import_in_order['response']][$item->response] = $this->link($item);
}
}
}
Expand Down Expand Up @@ -176,7 +177,7 @@ private function mapReferences()
$item = $data[1];


if (!isset($item->ref)) {
if (!isset($item->ref) || empty($item->ref)) {
$this->head_references[$import_name][] = &$data;
} elseif ($this->checkSyntax($item->ref)) {
$params = explode("/", $item->ref);
Expand Down Expand Up @@ -218,7 +219,7 @@ private function loadParent(&$child, $type, $parent_name)
/**
* Imports the references from all of the responses
*/
private function importReferences()
private function importReferences(Analysis $analysis)
{
foreach ($this->import_in_order as $key => $import_name) {
//get the list to import from
Expand All @@ -228,6 +229,12 @@ private function importReferences()
while (count($queue)) {
$this->iterateQueue($queue, $key);
}

// import, copy to swagger object
$analysis->swagger->$import_name = [];
foreach ($this->references[$import_name] as $item) {
$analysis->swagger->$import_name[] = $item[1];
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ResponseTest extends SwaggerTestCase
public function testMisspelledDefault()
{
$annotations = $this->parseComment('@SWG\Get(@SWG\Response(response="Default", description="description"))');
$this->assertSwaggerLogEntryStartsWith('Invalid value "Default" for @SWG\Response()->response, expecting "default" or a HTTP Status Code in ');
$this->assertSwaggerLogEntryStartsWith('Invalid value "Default" for @SWG\Response()->response, expecting "default" or a HTTP Status Code or $linkName in ');
$annotations[0]->validate();
}
}

0 comments on commit 5d333a5

Please sign in to comment.