Skip to content

Commit c3df6cf

Browse files
committed
Merge branch '2.3'
2 parents 7834b0f + 8313fb2 commit c3df6cf

File tree

6 files changed

+63
-2
lines changed

6 files changed

+63
-2
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## 2.3.2
4+
5+
* Open API/Swagger: detect correctly collection parameters
6+
* Open API/Swagger: fix serialization of nested objects when exporting as YAML
7+
* GraphQL: fix support of properties also mapped as subresources
8+
* GraphQL: fix retrieving the internal `_id` when `id` is not part of the requested fields
9+
* GraphQL: only exposes the mutations if any
10+
* Doctrine: prevent data duplication in Eager loaded relations
11+
* Preserve the host in the internal router
12+
313
## 2.3.1
414

515
* Data persisters: call only the 1st matching data persister, this fix may break existing code, see https://github.com/api-platform/docs/issues/540#issuecomment-405945358

src/Api/FilterInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface FilterInterface
2828
* - type: the type of the filter
2929
* - required: if this filter is required
3030
* - strategy: the used strategy
31+
* - is_collection (optional): is this filter is collection
3132
* - swagger (optional): additional parameters for the path operation,
3233
* e.g. 'swagger' => [
3334
* 'description' => 'My Description',

src/Bridge/Doctrine/Orm/Filter/SearchFilter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public function getDescription(string $resourceClass): array
112112
'type' => $typeOfField,
113113
'required' => false,
114114
'strategy' => $strategy,
115+
'is_collection' => '[]' === substr($filterParameterName, -2),
115116
];
116117
}
117118
} elseif ($metadata->hasAssociation($field)) {
@@ -126,6 +127,7 @@ public function getDescription(string $resourceClass): array
126127
'type' => 'string',
127128
'required' => false,
128129
'strategy' => self::STRATEGY_EXACT,
130+
'is_collection' => '[]' === substr($filterParameterName, -2),
129131
];
130132
}
131133
}

src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6767
{
6868
$documentation = new Documentation($this->resourceNameCollectionFactory->create(), $this->apiTitle, $this->apiDescription, $this->apiVersion, $this->apiFormats);
6969
$data = $this->documentationNormalizer->normalize($documentation);
70-
$content = $input->getOption('yaml') ? Yaml::dump($data) : json_encode($data, JSON_PRETTY_PRINT);
70+
$content = $input->getOption('yaml') ? Yaml::dump($data, Yaml::DUMP_OBJECT_AS_MAP) : json_encode($data, JSON_PRETTY_PRINT);
7171

7272
if (!empty($input->getOption('output'))) {
7373
file_put_contents($input->getOption('output'), $content);

src/Swagger/Serializer/DocumentationNormalizer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,11 @@ private function getFiltersParameters(string $resourceClass, string $operationNa
615615
'in' => 'query',
616616
'required' => $data['required'],
617617
];
618-
$parameter += $this->getType($data['type'], false, null, null, $definitions, $serializerContext);
618+
$parameter += $this->getType($data['type'], $data['is_collection'] ?? false, null, null, $definitions, $serializerContext);
619+
620+
if ('array' === $parameter['type']) {
621+
$parameter['collectionFormat'] = \in_array($data['type'], [Type::BUILTIN_TYPE_ARRAY, Type::BUILTIN_TYPE_OBJECT], true) ? 'csv' : 'multi';
622+
}
619623

620624
if (isset($data['swagger'])) {
621625
$parameter = $data['swagger'] + $parameter;

tests/Bridge/Doctrine/Orm/Filter/SearchFilterTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,144 +65,168 @@ public function testGetDescription()
6565
'type' => 'int',
6666
'required' => false,
6767
'strategy' => 'exact',
68+
'is_collection' => false,
6869
],
6970
'id[]' => [
7071
'property' => 'id',
7172
'type' => 'int',
7273
'required' => false,
7374
'strategy' => 'exact',
75+
'is_collection' => true,
7476
],
7577
'name' => [
7678
'property' => 'name',
7779
'type' => 'string',
7880
'required' => false,
7981
'strategy' => 'exact',
82+
'is_collection' => false,
8083
],
8184
'name[]' => [
8285
'property' => 'name',
8386
'type' => 'string',
8487
'required' => false,
8588
'strategy' => 'exact',
89+
'is_collection' => true,
8690
],
8791
'alias' => [
8892
'property' => 'alias',
8993
'type' => 'string',
9094
'required' => false,
9195
'strategy' => 'exact',
96+
'is_collection' => false,
9297
],
9398
'alias[]' => [
9499
'property' => 'alias',
95100
'type' => 'string',
96101
'required' => false,
97102
'strategy' => 'exact',
103+
'is_collection' => true,
98104
],
99105
'description' => [
100106
'property' => 'description',
101107
'type' => 'string',
102108
'required' => false,
103109
'strategy' => 'exact',
110+
'is_collection' => false,
104111
],
105112
'description[]' => [
106113
'property' => 'description',
107114
'type' => 'string',
108115
'required' => false,
109116
'strategy' => 'exact',
117+
'is_collection' => true,
110118
],
111119
'dummy' => [
112120
'property' => 'dummy',
113121
'type' => 'string',
114122
'required' => false,
115123
'strategy' => 'exact',
124+
'is_collection' => false,
116125
],
117126
'dummy[]' => [
118127
'property' => 'dummy',
119128
'type' => 'string',
120129
'required' => false,
121130
'strategy' => 'exact',
131+
'is_collection' => true,
122132
],
123133
'dummyDate' => [
124134
'property' => 'dummyDate',
125135
'type' => 'DateTimeInterface',
126136
'required' => false,
127137
'strategy' => 'exact',
138+
'is_collection' => false,
128139
],
129140
'dummyDate[]' => [
130141
'property' => 'dummyDate',
131142
'type' => 'DateTimeInterface',
132143
'required' => false,
133144
'strategy' => 'exact',
145+
'is_collection' => true,
134146
],
135147
'dummyFloat' => [
136148
'property' => 'dummyFloat',
137149
'type' => 'float',
138150
'required' => false,
139151
'strategy' => 'exact',
152+
'is_collection' => false,
140153
],
141154
'dummyFloat[]' => [
142155
'property' => 'dummyFloat',
143156
'type' => 'float',
144157
'required' => false,
145158
'strategy' => 'exact',
159+
'is_collection' => true,
146160
],
147161
'dummyPrice' => [
148162
'property' => 'dummyPrice',
149163
'type' => 'string',
150164
'required' => false,
151165
'strategy' => 'exact',
166+
'is_collection' => false,
152167
],
153168
'dummyPrice[]' => [
154169
'property' => 'dummyPrice',
155170
'type' => 'string',
156171
'required' => false,
157172
'strategy' => 'exact',
173+
'is_collection' => true,
158174
],
159175
'jsonData' => [
160176
'property' => 'jsonData',
161177
'type' => 'string',
162178
'required' => false,
163179
'strategy' => 'exact',
180+
'is_collection' => false,
164181
],
165182
'jsonData[]' => [
166183
'property' => 'jsonData',
167184
'type' => 'string',
168185
'required' => false,
169186
'strategy' => 'exact',
187+
'is_collection' => true,
170188
],
171189
'arrayData' => [
172190
'property' => 'arrayData',
173191
'type' => 'string',
174192
'required' => false,
175193
'strategy' => 'exact',
194+
'is_collection' => false,
176195
],
177196
'arrayData[]' => [
178197
'property' => 'arrayData',
179198
'type' => 'string',
180199
'required' => false,
181200
'strategy' => 'exact',
201+
'is_collection' => true,
182202
],
183203
'nameConverted' => [
184204
'property' => 'nameConverted',
185205
'type' => 'string',
186206
'required' => false,
187207
'strategy' => 'exact',
208+
'is_collection' => false,
188209
],
189210
'nameConverted[]' => [
190211
'property' => 'nameConverted',
191212
'type' => 'string',
192213
'required' => false,
193214
'strategy' => 'exact',
215+
'is_collection' => true,
194216
],
195217
'dummyBoolean' => [
196218
'property' => 'dummyBoolean',
197219
'type' => 'bool',
198220
'required' => false,
199221
'strategy' => 'exact',
222+
'is_collection' => false,
200223
],
201224
'dummyBoolean[]' => [
202225
'property' => 'dummyBoolean',
203226
'type' => 'bool',
204227
'required' => false,
205228
'strategy' => 'exact',
229+
'is_collection' => true,
206230
],
207231
], $filter->getDescription($this->resourceClass));
208232

@@ -226,120 +250,140 @@ public function testGetDescription()
226250
'type' => 'int',
227251
'required' => false,
228252
'strategy' => 'exact',
253+
'is_collection' => false,
229254
],
230255
'id[]' => [
231256
'property' => 'id',
232257
'type' => 'int',
233258
'required' => false,
234259
'strategy' => 'exact',
260+
'is_collection' => true,
235261
],
236262
'name' => [
237263
'property' => 'name',
238264
'type' => 'string',
239265
'required' => false,
240266
'strategy' => 'exact',
267+
'is_collection' => false,
241268
],
242269
'name[]' => [
243270
'property' => 'name',
244271
'type' => 'string',
245272
'required' => false,
246273
'strategy' => 'exact',
274+
'is_collection' => true,
247275
],
248276
'alias' => [
249277
'property' => 'alias',
250278
'type' => 'string',
251279
'required' => false,
252280
'strategy' => 'exact',
281+
'is_collection' => false,
253282
],
254283
'alias[]' => [
255284
'property' => 'alias',
256285
'type' => 'string',
257286
'required' => false,
258287
'strategy' => 'exact',
288+
'is_collection' => true,
259289
],
260290
'dummy' => [
261291
'property' => 'dummy',
262292
'type' => 'string',
263293
'required' => false,
264294
'strategy' => 'exact',
295+
'is_collection' => false,
265296
],
266297
'dummy[]' => [
267298
'property' => 'dummy',
268299
'type' => 'string',
269300
'required' => false,
270301
'strategy' => 'exact',
302+
'is_collection' => true,
271303
],
272304
'dummyDate' => [
273305
'property' => 'dummyDate',
274306
'type' => 'DateTimeInterface',
275307
'required' => false,
276308
'strategy' => 'exact',
309+
'is_collection' => false,
277310
],
278311
'dummyDate[]' => [
279312
'property' => 'dummyDate',
280313
'type' => 'DateTimeInterface',
281314
'required' => false,
282315
'strategy' => 'exact',
316+
'is_collection' => true,
283317
],
284318
'jsonData' => [
285319
'property' => 'jsonData',
286320
'type' => 'string',
287321
'required' => false,
288322
'strategy' => 'exact',
323+
'is_collection' => false,
289324
],
290325
'jsonData[]' => [
291326
'property' => 'jsonData',
292327
'type' => 'string',
293328
'required' => false,
294329
'strategy' => 'exact',
330+
'is_collection' => true,
295331
],
296332
'arrayData' => [
297333
'property' => 'arrayData',
298334
'type' => 'string',
299335
'required' => false,
300336
'strategy' => 'exact',
337+
'is_collection' => false,
301338
],
302339
'arrayData[]' => [
303340
'property' => 'arrayData',
304341
'type' => 'string',
305342
'required' => false,
306343
'strategy' => 'exact',
344+
'is_collection' => true,
307345
],
308346
'nameConverted' => [
309347
'property' => 'nameConverted',
310348
'type' => 'string',
311349
'required' => false,
312350
'strategy' => 'exact',
351+
'is_collection' => false,
313352
],
314353
'nameConverted[]' => [
315354
'property' => 'nameConverted',
316355
'type' => 'string',
317356
'required' => false,
318357
'strategy' => 'exact',
358+
'is_collection' => true,
319359
],
320360
'relatedDummies.dummyDate' => [
321361
'property' => 'relatedDummies.dummyDate',
322362
'type' => 'DateTimeInterface',
323363
'required' => false,
324364
'strategy' => 'exact',
365+
'is_collection' => false,
325366
],
326367
'relatedDummies.dummyDate[]' => [
327368
'property' => 'relatedDummies.dummyDate',
328369
'type' => 'DateTimeInterface',
329370
'required' => false,
330371
'strategy' => 'exact',
372+
'is_collection' => true,
331373
],
332374
'relatedDummy' => [
333375
'property' => 'relatedDummy',
334376
'type' => 'string',
335377
'required' => false,
336378
'strategy' => 'exact',
379+
'is_collection' => false,
337380
],
338381
'relatedDummy[]' => [
339382
'property' => 'relatedDummy',
340383
'type' => 'string',
341384
'required' => false,
342385
'strategy' => 'exact',
386+
'is_collection' => true,
343387
],
344388
], $filter->getDescription($this->resourceClass));
345389
}

0 commit comments

Comments
 (0)