Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 8f99524

Browse files
committed
magento-engcom/bulk-api#7 Add extension point to WebAPI
- fixed unit tests - changed matching algorithm for request processors
1 parent 7648131 commit 8f99524

File tree

4 files changed

+6
-28
lines changed

4 files changed

+6
-28
lines changed

app/code/Magento/Webapi/Controller/Rest/RequestProcessorInterface.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ interface RequestProcessorInterface
2222
*/
2323
public function process(\Magento\Framework\Webapi\Rest\Request $request);
2424

25-
/**
26-
* Return processor request prefix
27-
*
28-
* @return string
29-
*/
30-
public function getProcessorPath();
31-
3225
/**
3326
* Method should return true for all the request current processor can process.
3427
*

app/code/Magento/Webapi/Controller/Rest/SchemaRequestProcessor.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,19 @@ public function process(\Magento\Framework\Webapi\Rest\Request $request)
5454
$responseBody = $this->swaggerGenerator->generate(
5555
$requestedServices,
5656
$request->getScheme(),
57-
$request->getHttpHost(flase),
57+
$request->getHttpHost(false),
5858
$request->getRequestUri()
5959
);
6060
$this->response->setBody($responseBody)->setHeader('Content-Type', 'application/json');
6161
}
6262

63-
/**
64-
* {@inheritdoc}
65-
*/
66-
public function getProcessorPath()
67-
{
68-
return self::PROCESSOR_PATH;
69-
}
7063

7164
/**
7265
* {@inheritdoc}
7366
*/
7467
public function canProcess(\Magento\Framework\Webapi\Rest\Request $request)
7568
{
76-
if (strpos(ltrim($request->getPathInfo(), '/'), $this->getProcessorPath()) === 0) {
69+
if (strpos(ltrim($request->getPathInfo(), '/'), self::PROCESSOR_PATH) === 0) {
7770
return true;
7871
}
7972
return false;

app/code/Magento/Webapi/Controller/Rest/SynchronousRequestProcessor.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class SynchronousRequestProcessor implements RequestProcessorInterface
2020
{
21-
const PROCESSOR_PATH = 'V1';
21+
const PROCESSOR_PATH = "/V\n+/";
2222

2323
/**
2424
* @var RestResponse
@@ -107,20 +107,12 @@ public function process(\Magento\Framework\Webapi\Rest\Request $request)
107107
$this->response->prepareResponse($outputData);
108108
}
109109

110-
/**
111-
* {@inheritdoc}
112-
*/
113-
public function getProcessorPath()
114-
{
115-
return self::PROCESSOR_PATH;
116-
}
117-
118110
/**
119111
* {@inheritdoc}
120112
*/
121113
public function canProcess(\Magento\Framework\Webapi\Rest\Request $request)
122114
{
123-
if (strpos(ltrim($request->getPathInfo(), '/'), $this->getProcessorPath()) === 0) {
115+
if (preg_match(self::PROCESSOR_PATH, ltrim($request->getPathInfo(), '/')) === 0) {
124116
return true;
125117
}
126118
return false;

app/code/Magento/Webapi/Test/Unit/Controller/RestTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function testDispatchSchemaRequest()
192192

193193
$schema = 'Some REST schema content';
194194
$this->swaggerGeneratorMock->expects($this->any())->method('generate')->willReturn($schema);
195-
$this->requestProcessorPool->process($this->_requestMock);
195+
$this->requestProcessorPool->getProcessor($this->_requestMock)->process($this->_requestMock);
196196

197197
$this->assertEquals($schema, $this->_responseMock->getBody());
198198
}
@@ -225,7 +225,7 @@ public function testDispatchAllSchemaRequest()
225225

226226
$schema = 'Some REST schema content';
227227
$this->swaggerGeneratorMock->expects($this->any())->method('generate')->willReturn($schema);
228-
$this->requestProcessorPool->process($this->_requestMock);
228+
$this->requestProcessorPool->getProcessor($this->_requestMock)->process($this->_requestMock);
229229

230230
$this->assertEquals($schema, $this->_responseMock->getBody());
231231
}

0 commit comments

Comments
 (0)