Skip to content

Commit 01ca787

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1318 from magento-engcom/develop-prs
Public Pull Requests: #7446
2 parents 071c521 + 9156fca commit 01ca787

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,17 @@ protected function getGeneralInfo()
204204
protected function generatePathInfo($methodName, $httpMethodData, $tagName)
205205
{
206206
$methodData = $httpMethodData[Converter::KEY_METHOD];
207+
208+
$operationId = $this->typeProcessor->getOperationName($tagName, $methodData[Converter::KEY_METHOD]);
209+
$operationId .= ucfirst($methodName);
210+
207211
$pathInfo = [
208212
'tags' => [$tagName],
209213
'description' => $methodData['documentation'],
210-
'operationId' => $this->typeProcessor->getOperationName($tagName, $methodData[Converter::KEY_METHOD]) .
211-
ucfirst($methodName)
214+
'operationId' => $operationId,
212215
];
213216

214-
$parameters = $this->generateMethodParameters($httpMethodData);
217+
$parameters = $this->generateMethodParameters($httpMethodData, $operationId);
215218
if ($parameters) {
216219
$pathInfo['parameters'] = $parameters;
217220
}
@@ -265,11 +268,12 @@ protected function generateMethodResponses($methodData)
265268
* Generate parameters based on method data
266269
*
267270
* @param array $httpMethodData
271+
* @param string $operationId
268272
* @return array
269273
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
270274
* @SuppressWarnings(PHPMD.NPathComplexity)
271275
*/
272-
private function generateMethodParameters($httpMethodData)
276+
private function generateMethodParameters($httpMethodData, $operationId)
273277
{
274278
$bodySchema = [];
275279
$parameters = [];
@@ -335,7 +339,7 @@ private function generateMethodParameters($httpMethodData)
335339

336340
if ($bodySchema) {
337341
$bodyParam = [];
338-
$bodyParam['name'] = '$body';
342+
$bodyParam['name'] = $operationId . 'Body';
339343
$bodyParam['in'] = 'body';
340344
$bodyParam['schema'] = $bodySchema;
341345
$parameters[] = $bodyParam;

app/code/Magento/Webapi/Test/Unit/Model/Rest/Swagger/GeneratorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public function generateDataProvider()
223223
]
224224
],
225225
// @codingStandardsIgnoreStart
226-
'{"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"]}}}'
226+
'{"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"]}}}'
227227
// @codingStandardsIgnoreEnd
228228
],
229229
[

dev/tests/api-functional/testsuite/Magento/Webapi/JsonGenerationFromDataObjectTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Magento\TestFramework\Helper\Bootstrap;
1212
use Magento\Framework\App\ProductMetadataInterface;
13+
use Magento\Store\Model\StoreManagerInterface;
1314

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

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

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

4243
parent::setUp();
4344
}
@@ -197,7 +198,7 @@ public function getExpectedMultiServiceData()
197198
'required' => true
198199
],
199200
[
200-
'name' => '$body',
201+
'name' => 'testModule5AllSoapAndRestV1NestedUpdatePutBody',
201202
'in' => 'body',
202203
'schema' => [
203204
'required' => [

0 commit comments

Comments
 (0)