Skip to content

Commit

Permalink
Merge pull request #1318 from magento-engcom/develop-prs
Browse files Browse the repository at this point in the history
Public Pull Requests:

#7446
  • Loading branch information
Oleksii Korshenko authored Jul 12, 2017
2 parents 071c521 + 9156fca commit 01ca787
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
14 changes: 9 additions & 5 deletions app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,17 @@ protected function getGeneralInfo()
protected function generatePathInfo($methodName, $httpMethodData, $tagName)
{
$methodData = $httpMethodData[Converter::KEY_METHOD];

$operationId = $this->typeProcessor->getOperationName($tagName, $methodData[Converter::KEY_METHOD]);
$operationId .= ucfirst($methodName);

$pathInfo = [
'tags' => [$tagName],
'description' => $methodData['documentation'],
'operationId' => $this->typeProcessor->getOperationName($tagName, $methodData[Converter::KEY_METHOD]) .
ucfirst($methodName)
'operationId' => $operationId,
];

$parameters = $this->generateMethodParameters($httpMethodData);
$parameters = $this->generateMethodParameters($httpMethodData, $operationId);
if ($parameters) {
$pathInfo['parameters'] = $parameters;
}
Expand Down Expand Up @@ -265,11 +268,12 @@ protected function generateMethodResponses($methodData)
* Generate parameters based on method data
*
* @param array $httpMethodData
* @param string $operationId
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
private function generateMethodParameters($httpMethodData)
private function generateMethodParameters($httpMethodData, $operationId)
{
$bodySchema = [];
$parameters = [];
Expand Down Expand Up @@ -335,7 +339,7 @@ private function generateMethodParameters($httpMethodData)

if ($bodySchema) {
$bodyParam = [];
$bodyParam['name'] = '$body';
$bodyParam['name'] = $operationId . 'Body';
$bodyParam['in'] = 'body';
$bodyParam['schema'] = $bodySchema;
$parameters[] = $bodyParam;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function generateDataProvider()
]
],
// @codingStandardsIgnoreStart
'{"swagger":"2.0","info":{"version":"","title":""},"host":"magento.host","basePath":"/rest/default","schemes":["http://"],"tags":[{"name":"testModule5AllSoapAndRestV2","description":"AllSoapAndRestInterface"}],"paths":{"/V1/testModule5":{"post":{"tags":["testModule5AllSoapAndRestV2"],"description":"Add new item.","operationId":"' . self::OPERATION_NAME . 'Post","parameters":[{"name":"$body","in":"body","schema":{"required":["item"],"properties":{"item":{"$ref":"#/definitions/test-module5-v2-entity-all-soap-and-rest"}},"type":"object"}}],"responses":{"200":{"description":"200 Success.","schema":{"$ref":"#/definitions/test-module5-v2-entity-all-soap-and-rest"}},"401":{"description":"401 Unauthorized","schema":{"$ref":"#/definitions/error-response"}},"500":{"description":"Internal Server error","schema":{"$ref":"#/definitions/error-response"}},"default":{"description":"Unexpected error","schema":{"$ref":"#/definitions/error-response"}}}}}},"definitions":{"error-response":{"type":"object","properties":{"message":{"type":"string","description":"Error message"},"errors":{"$ref":"#/definitions/error-errors"},"code":{"type":"integer","description":"Error code"},"parameters":{"$ref":"#/definitions/error-parameters"},"trace":{"type":"string","description":"Stack trace"}},"required":["message"]},"error-errors":{"type":"array","description":"Errors list","items":{"$ref":"#/definitions/error-errors-item"}},"error-errors-item":{"type":"object","description":"Error details","properties":{"message":{"type":"string","description":"Error message"},"parameters":{"$ref":"#/definitions/error-parameters"}}},"error-parameters":{"type":"array","description":"Error parameters list","items":{"$ref":"#/definitions/error-parameters-item"}},"error-parameters-item":{"type":"object","description":"Error parameters item","properties":{"resources":{"type":"string","description":"ACL resource"},"fieldName":{"type":"string","description":"Missing or invalid field name"},"fieldValue":{"type":"string","description":"Incorrect field value"}}},"test-module5-v2-entity-all-soap-and-rest":{"type":"object","description":"Some Data Object","properties":{"price":{"type":"integer"}},"required":["price"]}}}'
'{"swagger":"2.0","info":{"version":"","title":""},"host":"magento.host","basePath":"/rest/default","schemes":["http://"],"tags":[{"name":"testModule5AllSoapAndRestV2","description":"AllSoapAndRestInterface"}],"paths":{"/V1/testModule5":{"post":{"tags":["testModule5AllSoapAndRestV2"],"description":"Add new item.","operationId":"' . self::OPERATION_NAME . 'Post","parameters":[{"name":"operationNamePostBody","in":"body","schema":{"required":["item"],"properties":{"item":{"$ref":"#/definitions/test-module5-v2-entity-all-soap-and-rest"}},"type":"object"}}],"responses":{"200":{"description":"200 Success.","schema":{"$ref":"#/definitions/test-module5-v2-entity-all-soap-and-rest"}},"401":{"description":"401 Unauthorized","schema":{"$ref":"#/definitions/error-response"}},"500":{"description":"Internal Server error","schema":{"$ref":"#/definitions/error-response"}},"default":{"description":"Unexpected error","schema":{"$ref":"#/definitions/error-response"}}}}}},"definitions":{"error-response":{"type":"object","properties":{"message":{"type":"string","description":"Error message"},"errors":{"$ref":"#/definitions/error-errors"},"code":{"type":"integer","description":"Error code"},"parameters":{"$ref":"#/definitions/error-parameters"},"trace":{"type":"string","description":"Stack trace"}},"required":["message"]},"error-errors":{"type":"array","description":"Errors list","items":{"$ref":"#/definitions/error-errors-item"}},"error-errors-item":{"type":"object","description":"Error details","properties":{"message":{"type":"string","description":"Error message"},"parameters":{"$ref":"#/definitions/error-parameters"}}},"error-parameters":{"type":"array","description":"Error parameters list","items":{"$ref":"#/definitions/error-parameters-item"}},"error-parameters-item":{"type":"object","description":"Error parameters item","properties":{"resources":{"type":"string","description":"ACL resource"},"fieldName":{"type":"string","description":"Missing or invalid field name"},"fieldValue":{"type":"string","description":"Incorrect field value"}}},"test-module5-v2-entity-all-soap-and-rest":{"type":"object","description":"Some Data Object","properties":{"price":{"type":"integer"}},"required":["price"]}}}'
// @codingStandardsIgnoreEnd
],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Magento\TestFramework\Helper\Bootstrap;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* Test REST schema generation mechanisms.
Expand All @@ -34,10 +35,10 @@ protected function setUp()
{
$this->_markTestAsRestOnly("JSON generation tests are intended to be executed for REST adapter only.");

$this->storeCode = Bootstrap::getObjectManager()->get(\Magento\Store\Model\StoreManagerInterface::class)
$this->storeCode = Bootstrap::getObjectManager()->get(StoreManagerInterface::class)
->getStore()->getCode();

$this->productMetadata = Bootstrap::getObjectManager()->get(\Magento\Framework\App\ProductMetadataInterface::class);
$this->productMetadata = Bootstrap::getObjectManager()->get(ProductMetadataInterface::class);

parent::setUp();
}
Expand Down Expand Up @@ -197,7 +198,7 @@ public function getExpectedMultiServiceData()
'required' => true
],
[
'name' => '$body',
'name' => 'testModule5AllSoapAndRestV1NestedUpdatePutBody',
'in' => 'body',
'schema' => [
'required' => [
Expand Down

0 comments on commit 01ca787

Please sign in to comment.