Skip to content

Commit

Permalink
Merge pull request #445 from magento-api/develop
Browse files Browse the repository at this point in the history
[API] Sprint 52 - Bugs Fixes
  • Loading branch information
orlangur committed Jul 11, 2015
2 parents c8b57ee + 6aae794 commit 5b465a2
Show file tree
Hide file tree
Showing 23 changed files with 176 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
*
* @param string $sku
* @param bool $editMode
* @param null|int $storeId
* @param int|null $storeId
* @param bool $forceReload
* @return \Magento\Catalog\Api\Data\ProductInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface GuestCartTotalManagementInterface
* Set shipping/billing methods and additional data for cart and collect totals for guest.
*
* @param string $cartId The cart ID.
* @param \Magento\Quote\Api\Data\PaymentInterface Payment method data.
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod Payment method data.
* @param string $shippingCarrierCode The carrier code.
* @param string $shippingMethodCode The shipping method code.
* @param \Magento\Quote\Api\Data\TotalsAdditionalDataInterface $additionalData Additional data to collect totals.
Expand Down
30 changes: 28 additions & 2 deletions app/code/Magento/Webapi/Controller/Soap.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ class Soap implements \Magento\Framework\App\FrontControllerInterface
protected $areaList;

/**
* Initialize dependencies.
*
* @var \Magento\Framework\Webapi\Rest\Response\RendererFactory
*/
protected $rendererFactory;

/**
* @param Soap\Request $request
* @param Response $response
* @param \Magento\Webapi\Model\Soap\Wsdl\Generator $wsdlGenerator
Expand All @@ -79,7 +82,9 @@ class Soap implements \Magento\Framework\App\FrontControllerInterface
* @param \Magento\Framework\App\State $appState
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
* @param PathProcessor $pathProcessor
* @param \Magento\Framework\Webapi\Rest\Response\RendererFactory $rendererFactory
* @param \Magento\Framework\App\AreaList $areaList
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
\Magento\Webapi\Controller\Soap\Request $request,
Expand All @@ -90,6 +95,7 @@ public function __construct(
\Magento\Framework\App\State $appState,
\Magento\Framework\Locale\ResolverInterface $localeResolver,
PathProcessor $pathProcessor,
\Magento\Framework\Webapi\Rest\Response\RendererFactory $rendererFactory,
\Magento\Framework\App\AreaList $areaList
) {
$this->_request = $request;
Expand All @@ -101,6 +107,7 @@ public function __construct(
$this->_localeResolver = $localeResolver;
$this->_pathProcessor = $pathProcessor;
$this->areaList = $areaList;
$this->rendererFactory = $rendererFactory;
}

/**
Expand All @@ -122,6 +129,15 @@ public function dispatch(\Magento\Framework\App\RequestInterface $request)
);
$this->_setResponseContentType(self::CONTENT_TYPE_WSDL_REQUEST);
$this->_setResponseBody($responseBody);
} else if ($this->_isWsdlListRequest()) {
$servicesList = [];
foreach (array_keys($this->_wsdlGenerator->getListOfServices()) as $serviceName) {
$servicesList[$serviceName]['wsdl_endpoint'] = $this->_soapServer->getEndpointUri()
. '?' . \Magento\Webapi\Model\Soap\Server::REQUEST_PARAM_WSDL . '&services=' . $serviceName;
}
$renderer = $this->rendererFactory->get();
$this->_setResponseContentType($renderer->getMimeType());
$this->_setResponseBody($renderer->render($servicesList));
} else {
$this->_soapServer->handle();
}
Expand All @@ -141,6 +157,16 @@ protected function _isWsdlRequest()
return $this->_request->getParam(\Magento\Webapi\Model\Soap\Server::REQUEST_PARAM_WSDL) !== null;
}

/**
* Check if current request is WSDL request. SOAP operation execution request is another type of requests.
*
* @return bool
*/
protected function _isWsdlListRequest()
{
return $this->_request->getParam(\Magento\Webapi\Model\Soap\Server::REQUEST_PARAM_LIST_WSDL) !== null;
}

/**
* Parse the Authorization header and return the access token e.g. Authorization: Bearer <access-token>
*
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Webapi/Model/Soap/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected function getSoapOperations($requestedServices)
*
* @return array
*/
protected function getSoapServicesConfig()
public function getSoapServicesConfig()
{
if (null === $this->soapServices) {
$soapServicesConfig = $this->cache->load(self::CACHE_ID);
Expand Down
33 changes: 14 additions & 19 deletions app/code/Magento/Webapi/Model/Soap/Config/ClassReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
namespace Magento\Webapi\Model\Soap\Config;

use Zend\Server\Reflection;
use Zend\Server\Reflection\ReflectionMethod;
use Zend\Code\Reflection\MethodReflection;

/**
Expand Down Expand Up @@ -66,8 +64,8 @@ public function __construct(\Magento\Framework\Reflection\TypeProcessor $typePro
public function reflectClassMethods($className, $methods)
{
$data = [];
$classReflection = new \Zend\Server\Reflection\ReflectionClass(new \ReflectionClass($className));
/** @var $methodReflection ReflectionMethod */
$classReflection = new \Zend\Code\Reflection\ClassReflection($className);
/** @var \Zend\Code\Reflection\MethodReflection $methodReflection */
foreach ($classReflection->getMethods() as $methodReflection) {
$methodName = $methodReflection->getName();
if (array_key_exists($methodName, $methods)) {
Expand All @@ -80,33 +78,30 @@ public function reflectClassMethods($className, $methods)
/**
* Retrieve method interface and documentation description.
*
* @param ReflectionMethod $method
* @param \Zend\Code\Reflection\MethodReflection $method
* @return array
* @throws \InvalidArgumentException
*/
public function extractMethodData(ReflectionMethod $method)
public function extractMethodData(\Zend\Code\Reflection\MethodReflection $method)
{
$methodData = ['documentation' => $this->extractMethodDescription($method), 'interface' => []];
$prototypes = $method->getPrototypes();
/** Take the fullest interface that also includes optional parameters. */
/** @var \Zend\Server\Reflection\Prototype $prototype */
$prototype = end($prototypes);
/** @var \Zend\Server\Reflection\ReflectionParameter $parameter */
foreach ($prototype->getParameters() as $parameter) {
/** @var \Zend\Code\Reflection\ParameterReflection $parameter */
foreach ($method->getParameters() as $parameter) {
$parameterData = [
'type' => $this->_typeProcessor->register($parameter->getType()),
'type' => $this->_typeProcessor->register($this->_typeProcessor->getParamType($parameter)),
'required' => !$parameter->isOptional(),
'documentation' => $parameter->getDescription(),
'documentation' => $this->_typeProcessor->getParamDescription($parameter),
];
if ($parameter->isOptional()) {
$parameterData['default'] = $parameter->getDefaultValue();
}
$methodData['interface']['in']['parameters'][$parameter->getName()] = $parameterData;
}
if ($prototype->getReturnType() != 'void' && $prototype->getReturnType() != 'null') {
$returnType = $this->_typeProcessor->getGetterReturnType($method);
if ($returnType != 'void' && $returnType != 'null') {
$methodData['interface']['out']['parameters']['result'] = [
'type' => $this->_typeProcessor->register($prototype->getReturnType()),
'documentation' => $prototype->getReturnValue()->getDescription(),
'type' => $this->_typeProcessor->register($returnType['type']),
'documentation' => $returnType['description'],
'required' => true,
];
}
Expand All @@ -117,10 +112,10 @@ public function extractMethodData(ReflectionMethod $method)
/**
* Retrieve method full documentation description.
*
* @param ReflectionMethod $method
* @param \Zend\Code\Reflection\MethodReflection $method
* @return string
*/
protected function extractMethodDescription(ReflectionMethod $method)
protected function extractMethodDescription(\Zend\Code\Reflection\MethodReflection $method)
{
$methodReflection = new MethodReflection(
$method->getDeclaringClass()->getName(),
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Webapi/Model/Soap/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Server

const REQUEST_PARAM_WSDL = 'wsdl';

const REQUEST_PARAM_LIST_WSDL = 'wsdl_list';

/**
* @var \Magento\Framework\App\AreaLIst
*/
Expand Down
10 changes: 10 additions & 0 deletions app/code/Magento/Webapi/Model/Soap/Wsdl/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ public function __construct(
$this->customAttributeTypeLocator = $customAttributeTypeLocator;
}

/**
* Retrieve an array of services
*
* @return array
*/
public function getListOfServices()
{
return $this->_apiConfig->getSoapServicesConfig();
}

/**
* Generate WSDL file based on requested services (uses cache)
*
Expand Down
13 changes: 12 additions & 1 deletion app/code/Magento/Webapi/Test/Unit/Controller/SoapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class SoapTest extends \PHPUnit_Framework_TestCase
*/
protected $_localeMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\State
*/
protected $_appStateMock;

/**
* Set up Controller object.
*/
Expand Down Expand Up @@ -71,7 +76,8 @@ protected function setUp()
->disableOriginalConstructor()
->setMethods(['maskException'])
->getMock();
$this->_appStateMock = $this->getMock('\Magento\Framework\App\State', [], [], '', false);

$this->_appStateMock = $this->getMock('Magento\Framework\App\State', [], [], '', false);

$localeResolverMock = $this->getMockBuilder(
'Magento\Framework\Locale\Resolver'
Expand All @@ -93,6 +99,10 @@ protected function setUp()
$areaListMock = $this->getMock('Magento\Framework\App\AreaList', [], [], '', false);
$areaMock = $this->getMock('Magento\Framework\App\AreaInterface');
$areaListMock->expects($this->any())->method('getArea')->will($this->returnValue($areaMock));

$rendererMock = $this->getMockBuilder('Magento\Framework\Webapi\Rest\Response\RendererFactory')
->disableOriginalConstructor()
->getMock();
$this->_soapController = new \Magento\Webapi\Controller\Soap(
$this->_requestMock,
$this->_responseMock,
Expand All @@ -102,6 +112,7 @@ protected function setUp()
$this->_appStateMock,
$localeResolverMock,
$pathProcessorMock,
$rendererMock,
$areaListMock
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public function testReflectClassMethods()

public function testExtractMethodData()
{
$classReflection = new \Zend\Server\Reflection\ReflectionClass(
new \ReflectionClass('\\Magento\\Webapi\\Test\\Unit\\Model\\Config\\TestServiceForClassReflector')
$classReflection = new \Zend\Code\Reflection\ClassReflection(
'\\Magento\\Webapi\\Test\\Unit\\Model\\Config\\TestServiceForClassReflector'
);
/** @var $methodReflection ReflectionMethod */
/** @var $methodReflection \Zend\Code\Reflection\MethodReflection */
$methodReflection = $classReflection->getMethods()[0];
$methodData = $this->_classReflector->extractMethodData($methodReflection);
$expectedResponse = $this->_getSampleReflectionData();
Expand Down
26 changes: 26 additions & 0 deletions app/code/Magento/Webapi/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,30 @@
</argument>
</arguments>
</type>
<type name="Magento\Framework\Webapi\Rest\Response\RendererFactory">
<arguments>
<argument name="renders" xsi:type="array">
<item name="default" xsi:type="array">
<item name="type" xsi:type="string">*/*</item>
<item name="model" xsi:type="string">Magento\Framework\Webapi\Rest\Response\Renderer\Json</item>
</item>
<item name="application_json" xsi:type="array">
<item name="type" xsi:type="string">application/json</item>
<item name="model" xsi:type="string">Magento\Framework\Webapi\Rest\Response\Renderer\Json</item>
</item>
<item name="text_xml" xsi:type="array">
<item name="type" xsi:type="string">text/xml</item>
<item name="model" xsi:type="string">Magento\Framework\Webapi\Rest\Response\Renderer\Xml</item>
</item>
<item name="application_xml" xsi:type="array">
<item name="type" xsi:type="string">application/xml</item>
<item name="model" xsi:type="string">Magento\Framework\Webapi\Rest\Response\Renderer\Xml</item>
</item>
<item name="application_xhtml_xml" xsi:type="array">
<item name="type" xsi:type="string">application/xhtml+xml</item>
<item name="model" xsi:type="string">Magento\Framework\Webapi\Rest\Response\Renderer\Xml</item>
</item>
</argument>
</arguments>
</type>
</config>
26 changes: 0 additions & 26 deletions app/code/Magento/Webapi/etc/webapi_rest/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,6 @@
<preference for="Magento\Framework\App\FrontControllerInterface" type="Magento\Webapi\Controller\Rest" />
<preference for="Magento\Framework\Model\ActionValidator\RemoveAction" type="Magento\Framework\Model\ActionValidator\RemoveAction\Allowed" />
<type name="Magento\Webapi\Controller\Rest\Router\Route" shared="false" />
<type name="Magento\Framework\Webapi\Rest\Response\RendererFactory">
<arguments>
<argument name="renders" xsi:type="array">
<item name="default" xsi:type="array">
<item name="type" xsi:type="string">*/*</item>
<item name="model" xsi:type="string">Magento\Framework\Webapi\Rest\Response\Renderer\Json</item>
</item>
<item name="application_json" xsi:type="array">
<item name="type" xsi:type="string">application/json</item>
<item name="model" xsi:type="string">Magento\Framework\Webapi\Rest\Response\Renderer\Json</item>
</item>
<item name="text_xml" xsi:type="array">
<item name="type" xsi:type="string">text/xml</item>
<item name="model" xsi:type="string">Magento\Framework\Webapi\Rest\Response\Renderer\Xml</item>
</item>
<item name="application_xml" xsi:type="array">
<item name="type" xsi:type="string">application/xml</item>
<item name="model" xsi:type="string">Magento\Framework\Webapi\Rest\Response\Renderer\Xml</item>
</item>
<item name="application_xhtml_xml" xsi:type="array">
<item name="type" xsi:type="string">application/xhtml+xml</item>
<item name="model" xsi:type="string">Magento\Framework\Webapi\Rest\Response\Renderer\Xml</item>
</item>
</argument>
</arguments>
</type>
<type name="Magento\Webapi\Controller\Rest">
<arguments>
<argument name="request" xsi:type="object">Magento\Framework\Webapi\Rest\Request\Proxy</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestJoinDirectives\Api;
namespace Magento\TestModuleJoinDirectives\Api;

/**
* Interface TestRepositoryInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestJoinDirectives\Model;
namespace Magento\TestModuleJoinDirectives\Model;

use Magento\TestJoinDirectives\Api\TestRepositoryInterface;
use Magento\TestModuleJoinDirectives\Api\TestRepositoryInterface;
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<acl>
<resources>
<resource id="Magento_Backend::admin">
<resource id="Magento_TestJoinDirectives::all" title="TestJoinDirectives" sortOrder="1">
<resource id="Magento_TestJoinDirectives::getList" title="GetList" sortOrder="10"/>
<resource id="Magento_TestModuleJoinDirectives::all" title="TestJoinDirectives" sortOrder="1">
<resource id="Magento_TestModuleJoinDirectives::getList" title="GetList" sortOrder="10"/>
</resource>
</resource>
</resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<preference for="Magento\TestJoinDirectives\Api\TestRepositoryInterface" type="Magento\TestJoinDirectives\Model\TestRepository" />
<preference for="Magento\TestModuleJoinDirectives\Api\TestRepositoryInterface" type="Magento\TestModuleJoinDirectives\Model\TestRepository" />
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Magento_TestJoinDirectives" setup_version="1.0"/>
<module name="Magento_TestModuleJoinDirectives" setup_version="1.0"/>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../app/code/Magento/Webapi/etc/webapi.xsd">

<route url="/V1/TestJoinDirectives" method="GET">
<service class="Magento\TestJoinDirectives\Api\TestRepositoryInterface" method="getList"/>
<route url="/V1/TestModuleJoinDirectives" method="GET">
<service class="Magento\TestModuleJoinDirectives\Api\TestRepositoryInterface" method="getList"/>
<resources>
<resource ref="Magento_TestJoinDirectives::getList" />
<resource ref="Magento_TestModuleJoinDirectives::getList" />
</resources>
</route>
</routes>
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function testGetList()
$searchCriteria = $this->searchBuilder->create()->__toArray();
$requestData = ['searchCriteria' => $searchCriteria];

$restResourcePath = '/V1/TestJoinDirectives/';
$soapService = 'testJoinDirectivesTestRepositoryV1';
$restResourcePath = '/V1/TestModuleJoinDirectives/';
$soapService = 'testModuleJoinDirectivesTestRepositoryV1';
$expectedExtensionAttributes = $this->getExpectedExtensionAttributes();

$serviceInfo = [
Expand Down
Loading

0 comments on commit 5b465a2

Please sign in to comment.