Skip to content

Commit 5443f9d

Browse files
author
Eugene Tulika
committed
MAGETWO-38070 Incorrect WSDL generation
1 parent 2015f5c commit 5443f9d

File tree

5 files changed

+45
-22
lines changed

5 files changed

+45
-22
lines changed

app/code/Magento/Catalog/Api/ProductRepositoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
2929
*
3030
* @param string $sku
3131
* @param bool $editMode
32-
* @param null|int $storeId
32+
* @param int|null $storeId
3333
* @param bool $forceReload
3434
* @return \Magento\Catalog\Api\Data\ProductInterface
3535
* @throws \Magento\Framework\Exception\NoSuchEntityException

app/code/Magento/Quote/Api/GuestCartTotalManagementInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface GuestCartTotalManagementInterface
1414
* Set shipping/billing methods and additional data for cart and collect totals for guest.
1515
*
1616
* @param string $cartId The cart ID.
17-
* @param \Magento\Quote\Api\Data\PaymentInterface Payment method data.
17+
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod Payment method data.
1818
* @param string $shippingCarrierCode The carrier code.
1919
* @param string $shippingMethodCode The shipping method code.
2020
* @param \Magento\Quote\Api\Data\TotalsAdditionalDataInterface $additionalData Additional data to collect totals.

app/code/Magento/Webapi/Model/Soap/Config/ClassReflector.php

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
namespace Magento\Webapi\Model\Soap\Config;
77

8-
use Zend\Server\Reflection;
9-
use Zend\Server\Reflection\ReflectionMethod;
108
use Zend\Code\Reflection\MethodReflection;
119

1210
/**
@@ -66,8 +64,8 @@ public function __construct(\Magento\Framework\Reflection\TypeProcessor $typePro
6664
public function reflectClassMethods($className, $methods)
6765
{
6866
$data = [];
69-
$classReflection = new \Zend\Server\Reflection\ReflectionClass(new \ReflectionClass($className));
70-
/** @var $methodReflection ReflectionMethod */
67+
$classReflection = new \Zend\Code\Reflection\ClassReflection($className);
68+
/** @var \Zend\Code\Reflection\MethodReflection $methodReflection */
7169
foreach ($classReflection->getMethods() as $methodReflection) {
7270
$methodName = $methodReflection->getName();
7371
if (array_key_exists($methodName, $methods)) {
@@ -80,33 +78,30 @@ public function reflectClassMethods($className, $methods)
8078
/**
8179
* Retrieve method interface and documentation description.
8280
*
83-
* @param ReflectionMethod $method
81+
* @param \Zend\Code\Reflection\MethodReflection $method
8482
* @return array
8583
* @throws \InvalidArgumentException
8684
*/
87-
public function extractMethodData(ReflectionMethod $method)
85+
public function extractMethodData(\Zend\Code\Reflection\MethodReflection $method)
8886
{
8987
$methodData = ['documentation' => $this->extractMethodDescription($method), 'interface' => []];
90-
$prototypes = $method->getPrototypes();
91-
/** Take the fullest interface that also includes optional parameters. */
92-
/** @var \Zend\Server\Reflection\Prototype $prototype */
93-
$prototype = end($prototypes);
94-
/** @var \Zend\Server\Reflection\ReflectionParameter $parameter */
95-
foreach ($prototype->getParameters() as $parameter) {
88+
/** @var \Zend\Code\Reflection\ParameterReflection $parameter */
89+
foreach ($method->getParameters() as $parameter) {
9690
$parameterData = [
97-
'type' => $this->_typeProcessor->register($parameter->getType()),
91+
'type' => $this->_typeProcessor->register($this->_typeProcessor->getParamType($parameter)),
9892
'required' => !$parameter->isOptional(),
99-
'documentation' => $parameter->getDescription(),
93+
'documentation' => $this->_typeProcessor->getParamDescription($parameter),
10094
];
10195
if ($parameter->isOptional()) {
10296
$parameterData['default'] = $parameter->getDefaultValue();
10397
}
10498
$methodData['interface']['in']['parameters'][$parameter->getName()] = $parameterData;
10599
}
106-
if ($prototype->getReturnType() != 'void' && $prototype->getReturnType() != 'null') {
100+
$returnType = $this->_typeProcessor->getGetterReturnType($method);
101+
if ($returnType != 'void' && $returnType != 'null') {
107102
$methodData['interface']['out']['parameters']['result'] = [
108-
'type' => $this->_typeProcessor->register($prototype->getReturnType()),
109-
'documentation' => $prototype->getReturnValue()->getDescription(),
103+
'type' => $this->_typeProcessor->register($returnType['type']),
104+
'documentation' => $returnType['description'],
110105
'required' => true,
111106
];
112107
}
@@ -117,10 +112,10 @@ public function extractMethodData(ReflectionMethod $method)
117112
/**
118113
* Retrieve method full documentation description.
119114
*
120-
* @param ReflectionMethod $method
115+
* @param \Zend\Code\Reflection\MethodReflection $method
121116
* @return string
122117
*/
123-
protected function extractMethodDescription(ReflectionMethod $method)
118+
protected function extractMethodDescription(\Zend\Code\Reflection\MethodReflection $method)
124119
{
125120
$methodReflection = new MethodReflection(
126121
$method->getDeclaringClass()->getName(),

app/code/Magento/Webapi/Model/Soap/Wsdl/Generator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ protected function _generate($requestedServices, $endPointUrl)
167167
$wsdl->addSoapOperation($bindingOperation, $operationName, SOAP_1_2);
168168
}
169169
}
170-
return $wsdl->toXML();
170+
$dom = $wsdl->toDomDocument();
171+
$dom->formatOutput = true;
172+
return $dom->saveXML();
171173
}
172174

173175
/**

lib/internal/Magento/Framework/Reflection/TypeProcessor.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,14 +473,24 @@ public function processSimpleAndAnyType($value, $type)
473473
*
474474
* @param ParameterReflection $param
475475
* @return string
476+
* @throws \Exception
476477
*/
477478
public function getParamType(ParameterReflection $param)
478479
{
479480
$type = $param->getType();
481+
if ($param->getType() == 'null') {
482+
throw new \Exception(sprintf(
483+
'Type declaration is incorrect for the parameter "%s" in annotation for a method in the class "%s".'
484+
. ' First declared type should not be null. E.g. string|null',
485+
$param->getName(),
486+
$param->getDeclaringClass()->getName()
487+
));
488+
}
480489
if ($type == 'array') {
481490
// try to determine class, if it's array of objects
482491
$docBlock = $param->getDeclaringFunction()->getDocBlock();
483492
$pattern = "/\@param\s+([\w\\\_]+\[\])\s+\\\${$param->getName()}\n/";
493+
$matches = [];
484494
if (preg_match($pattern, $docBlock->getContents(), $matches)) {
485495
return $matches[1];
486496
}
@@ -489,6 +499,22 @@ public function getParamType(ParameterReflection $param)
489499
return $type;
490500
}
491501

502+
/**
503+
* Get parameter description
504+
*
505+
* @param ParameterReflection $param
506+
* @return mixed
507+
*/
508+
public function getParamDescription(ParameterReflection $param)
509+
{
510+
$docBlock = $param->getDeclaringFunction()->getDocBlock();
511+
$pattern = "/\@param\s+([\w\\\_\[\]]+)\s+(\\\${$param->getName()})(.*)\n/";
512+
$matches = [];
513+
if (preg_match($pattern, $docBlock->getContents(), $matches)) {
514+
return $matches[3];
515+
}
516+
}
517+
492518
/**
493519
* Find the getter method name for a property from the given class
494520
*

0 commit comments

Comments
 (0)