Skip to content

Commit 9bbbf04

Browse files
author
al.kravchuk
committed
#24626: Webapi Swager schema generation fail in case when Get endpoint has param with Extension Attributes [Case#2].
Add unit tests coverage.
1 parent 7e30a18 commit 9bbbf04

File tree

1 file changed

+114
-17
lines changed

1 file changed

+114
-17
lines changed

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

Lines changed: 114 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Webapi\Test\Unit\Model\Rest\Swagger;
78

89
/**
@@ -137,11 +138,7 @@ public function testGenerate($serviceMetadata, $typeData, $schema)
137138
->willReturn($serviceMetadata);
138139
$this->typeProcessorMock->expects($this->any())
139140
->method('getTypeData')
140-
->willReturnMap(
141-
[
142-
['TestModule5V2EntityAllSoapAndRest', $typeData],
143-
]
144-
);
141+
->willReturnMap($typeData);
145142

146143
$this->typeProcessorMock->expects($this->any())
147144
->method('isTypeSimple')
@@ -169,6 +166,96 @@ public function testGenerate($serviceMetadata, $typeData, $schema)
169166
public function generateDataProvider()
170167
{
171168
return [
169+
[
170+
[
171+
'methods' => [
172+
'execute' => [
173+
'method' => 'execute',
174+
'inputRequired' => false,
175+
'isSecure' => false,
176+
'resources' => [
177+
"anonymous"
178+
],
179+
'methodAlias' => 'execute',
180+
'parameters' => [],
181+
'documentation' => 'Do Magic!',
182+
'interface' => [
183+
'in' => [
184+
'parameters' => [
185+
'searchRequest' => [
186+
'type' => 'DreamVendorDreamModuleApiDataSearchRequestInterface',
187+
'required' => true,
188+
'documentation' => ""
189+
]
190+
]
191+
],
192+
'out' => [
193+
'parameters' => [
194+
'result' => [
195+
'type' => 'DreamVendorDreamModuleApiDataSearchResultInterface',
196+
'documentation' => null,
197+
'required' => true
198+
]
199+
]
200+
]
201+
]
202+
]
203+
],
204+
'class' => 'DreamVendor\DreamModule\Api\ExecuteStuff',
205+
'description' => '',
206+
'routes' => [
207+
'/V1/dream-vendor/dream-module/execute-stuff' => [
208+
'GET' => [
209+
'method' => 'execute',
210+
'parameters' => []
211+
]
212+
]
213+
]
214+
],
215+
[
216+
[
217+
'DreamVendorDreamModuleApiDataSearchRequestInterface',
218+
[
219+
'documentation' => '',
220+
'parameters' => [
221+
'stuff' => [
222+
'type' => 'DreamVendorDreamModuleApiDataStuffInterface',
223+
'required' => true,
224+
'documentation' => 'Empty Extension Point'
225+
]
226+
]
227+
]
228+
],
229+
[
230+
'DreamVendorDreamModuleApiDataSearchResultInterface',
231+
[
232+
'documentation' => '',
233+
'parameters' => [
234+
'totalCount' => [
235+
'type' => 'int',
236+
'required' => true,
237+
'documentation' => 'Processed count.'
238+
],
239+
'stuff' => [
240+
'type' => 'DreamVendorDreamModuleApiDataStuffInterface',
241+
'required' => true,
242+
'documentation' => 'Empty Extension Point'
243+
]
244+
]
245+
]
246+
],
247+
[
248+
'DreamVendorDreamModuleApiDataStuffInterface',
249+
[
250+
'documentation' => '',
251+
'parameters' => []
252+
]
253+
]
254+
],
255+
// @codingStandardsIgnoreStart
256+
'{"swagger":"2.0","info":{"version":"","title":""},"host":"magento.host","basePath":"/rest/default","schemes":["http://"],"tags":[{"name":"testModule5AllSoapAndRestV2","description":""}],"paths":{"/V1/dream-vendor/dream-module/execute-stuff":{"get":{"tags":["testModule5AllSoapAndRestV2"],"description":"Do Magic!","operationId":"operationNameGet","consumes":["application/json","application/xml"],"produces":["application/json","application/xml"],"responses":{"200":{"description":"200 Success.","schema":{"$ref":"#/definitions/dream-vendor-dream-module-api-data-search-result-interface"}},"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"}}},"dream-vendor-dream-module-api-data-search-result-interface":{"type":"object","description":"","properties":{"total_count":{"type":"integer","description":"Processed count."},"stuff":{"$ref":"#/definitions/dream-vendor-dream-module-api-data-stuff-interface"}},"required":["total_count","stuff"]},"dream-vendor-dream-module-api-data-stuff-interface":{"type":"object","description":""}}}'
257+
// @codingStandardsIgnoreEnd
258+
],
172259
[
173260
[
174261
'methods' => [
@@ -213,12 +300,17 @@ public function generateDataProvider()
213300
],
214301
],
215302
[
216-
'documentation' => 'Some Data Object',
217-
'parameters' => [
218-
'price' => [
219-
'type' => 'int',
220-
'required' => true,
221-
'documentation' => ""
303+
[
304+
'TestModule5V2EntityAllSoapAndRest',
305+
[
306+
'documentation' => 'Some Data Object',
307+
'parameters' => [
308+
'price' => [
309+
'type' => 'int',
310+
'required' => true,
311+
'documentation' => ""
312+
]
313+
]
222314
]
223315
]
224316
],
@@ -261,12 +353,17 @@ public function generateDataProvider()
261353
],
262354
],
263355
[
264-
'documentation' => 'Some Data Object',
265-
'parameters' => [
266-
'price' => [
267-
'type' => 'int',
268-
'required' => true,
269-
'documentation' => ""
356+
[
357+
'TestModule5V2EntityAllSoapAndRest',
358+
[
359+
'documentation' => 'Some Data Object',
360+
'parameters' => [
361+
'price' => [
362+
'type' => 'int',
363+
'required' => true,
364+
'documentation' => ""
365+
]
366+
]
270367
]
271368
]
272369
],

0 commit comments

Comments
 (0)