Skip to content

Commit 0e3f820

Browse files
authored
fix: 422 is not defined in the documentation (#4086)
1 parent e7bde8f commit 0e3f820

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-0
lines changed

CHANGELOG.md

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

3+
# 2.6.4
4+
5+
* OpenApi: Fix missing 422 responses in the documentation (#4086)
6+
37
## 2.6.3
48

59
* Identifiers: Re-allow `POST` operations even if no identifier is defined (#4052)

src/OpenApi/Factory/OpenApiFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ private function collectPaths(ResourceMetadata $resourceMetadata, string $resour
204204
$successStatus = (string) $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'status', '201');
205205
$responses[$successStatus] = new Model\Response(sprintf('%s resource created', $resourceShortName), $responseContent, null, $responseLinks);
206206
$responses['400'] = new Model\Response('Invalid input');
207+
$responses['422'] = new Model\Response('Unprocessable entity');
207208
break;
208209
case 'PATCH':
209210
case 'PUT':
@@ -212,6 +213,7 @@ private function collectPaths(ResourceMetadata $resourceMetadata, string $resour
212213
$responseContent = $this->buildContent($responseMimeTypes, $operationOutputSchemas);
213214
$responses[$successStatus] = new Model\Response(sprintf('%s resource updated', $resourceShortName), $responseContent, null, $responseLinks);
214215
$responses['400'] = new Model\Response('Invalid input');
216+
$responses['422'] = new Model\Response('Unprocessable entity');
215217
break;
216218
case 'DELETE':
217219
$successStatus = (string) $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'status', '204');

src/Swagger/Serializer/DocumentationNormalizer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ private function updatePostOperation(bool $v3, \ArrayObject $pathOperation, arra
526526
(string) $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'status', '201') => $successResponse,
527527
'400' => ['description' => 'Invalid input'],
528528
'404' => ['description' => 'Resource not found'],
529+
'422' => ['description' => 'Unprocessable entity'],
529530
];
530531

531532
return $this->addRequestBody($v3, $pathOperation, $definitions, $resourceClass, $resourceShortName, $operationType, $operationName, $requestMimeTypes);
@@ -549,6 +550,7 @@ private function updatePutOperation(bool $v3, \ArrayObject $pathOperation, array
549550
(string) $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'status', '200') => $successResponse,
550551
'400' => ['description' => 'Invalid input'],
551552
'404' => ['description' => 'Resource not found'],
553+
'422' => ['description' => 'Unprocessable entity'],
552554
];
553555

554556
return $this->addRequestBody($v3, $pathOperation, $definitions, $resourceClass, $resourceShortName, $operationType, $operationName, $requestMimeTypes, true);

tests/OpenApi/Factory/OpenApiFactoryTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ public function testInvoke(): void
317317
new \ArrayObject(['GetDummyItem' => new Model\Link('getDummyItem', new \ArrayObject(['id' => '$response.body#/id']), [], 'The `id` value returned in the response can be used as the `id` parameter in `GET /dummies/{id}`.')])
318318
),
319319
'400' => new Model\Response('Invalid input'),
320+
'422' => new Model\Response('Unprocessable entity'),
320321
],
321322
'Creates a Dummy resource.',
322323
'Creates a Dummy resource.',
@@ -368,6 +369,7 @@ public function testInvoke(): void
368369
new \ArrayObject(['GetDummyItem' => new Model\Link('getDummyItem', new \ArrayObject(['id' => '$response.body#/id']), [], 'The `id` value returned in the response can be used as the `id` parameter in `GET /dummies/{id}`.')])
369370
),
370371
'400' => new Model\Response('Invalid input'),
372+
'422' => new Model\Response('Unprocessable entity'),
371373
'404' => new Model\Response('Resource not found'),
372374
],
373375
'Replaces the Dummy resource.',
@@ -437,6 +439,7 @@ public function testInvoke(): void
437439
new \ArrayObject(['GetDummyItem' => new Model\Link('getDummyItem', new \ArrayObject(['id' => '$response.body#/id']), [], 'The `id` value returned in the response can be used as the `id` parameter in `GET /dummies/{id}`.')])
438440
),
439441
'400' => new Model\Response('Invalid input'),
442+
'422' => new Model\Response('Unprocessable entity'),
440443
'404' => new Model\Response('Resource not found'),
441444
],
442445
'Replaces the Dummy resource.',

tests/Swagger/Serializer/DocumentationNormalizerV2Test.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ private function doTestNormalize(OperationMethodResolverInterface $operationMeth
241241
],
242242
400 => ['description' => 'Invalid input'],
243243
404 => ['description' => 'Resource not found'],
244+
422 => ['description' => 'Unprocessable entity'],
244245
],
245246
]),
246247
],
@@ -293,6 +294,7 @@ private function doTestNormalize(OperationMethodResolverInterface $operationMeth
293294
],
294295
400 => ['description' => 'Invalid input'],
295296
404 => ['description' => 'Resource not found'],
297+
422 => ['description' => 'Unprocessable entity'],
296298
],
297299
]),
298300
],
@@ -349,6 +351,7 @@ private function doTestNormalize(OperationMethodResolverInterface $operationMeth
349351
],
350352
400 => ['description' => 'Invalid input'],
351353
404 => ['description' => 'Resource not found'],
354+
422 => ['description' => 'Unprocessable entity'],
352355
],
353356
]),
354357
],
@@ -791,6 +794,7 @@ public function testNormalizeWithOnlyNormalizationGroups(): void
791794
],
792795
400 => ['description' => 'Invalid input'],
793796
404 => ['description' => 'Resource not found'],
797+
422 => ['description' => 'Unprocessable entity'],
794798
],
795799
]),
796800
],
@@ -841,6 +845,7 @@ public function testNormalizeWithOnlyNormalizationGroups(): void
841845
],
842846
400 => ['description' => 'Invalid input'],
843847
404 => ['description' => 'Resource not found'],
848+
422 => ['description' => 'Unprocessable entity'],
844849
],
845850
]),
846851
],
@@ -1013,6 +1018,7 @@ public function testNormalizeNotAddExtraBodyParameters(): void
10131018
],
10141019
400 => ['description' => 'Invalid input'],
10151020
404 => ['description' => 'Resource not found'],
1021+
422 => ['description' => 'Unprocessable entity'],
10161022
],
10171023
]),
10181024
],
@@ -1063,6 +1069,7 @@ public function testNormalizeNotAddExtraBodyParameters(): void
10631069
],
10641070
400 => ['description' => 'Invalid input'],
10651071
404 => ['description' => 'Resource not found'],
1072+
422 => ['description' => 'Unprocessable entity'],
10661073
],
10671074
]),
10681075
],
@@ -1333,6 +1340,7 @@ public function testNormalizeWithOnlyDenormalizationGroups(): void
13331340
],
13341341
400 => ['description' => 'Invalid input'],
13351342
404 => ['description' => 'Resource not found'],
1343+
422 => ['description' => 'Unprocessable entity'],
13361344
],
13371345
]),
13381346
],
@@ -1383,6 +1391,7 @@ public function testNormalizeWithOnlyDenormalizationGroups(): void
13831391
],
13841392
400 => ['description' => 'Invalid input'],
13851393
404 => ['description' => 'Resource not found'],
1394+
422 => ['description' => 'Unprocessable entity'],
13861395
],
13871396
]),
13881397
],
@@ -1543,6 +1552,7 @@ public function testNormalizeWithNormalizationAndDenormalizationGroups(): void
15431552
],
15441553
400 => ['description' => 'Invalid input'],
15451554
404 => ['description' => 'Resource not found'],
1555+
422 => ['description' => 'Unprocessable entity'],
15461556
],
15471557
]),
15481558
],
@@ -1593,6 +1603,7 @@ public function testNormalizeWithNormalizationAndDenormalizationGroups(): void
15931603
],
15941604
400 => ['description' => 'Invalid input'],
15951605
404 => ['description' => 'Resource not found'],
1606+
422 => ['description' => 'Unprocessable entity'],
15961607
],
15971608
]),
15981609
],
@@ -1752,6 +1763,7 @@ public function testNormalizeSkipsNotReadableAndNotWritableProperties(): void
17521763
],
17531764
400 => ['description' => 'Invalid input'],
17541765
404 => ['description' => 'Resource not found'],
1766+
422 => ['description' => 'Unprocessable entity'],
17551767
],
17561768
]),
17571769
],
@@ -1804,6 +1816,7 @@ public function testNormalizeSkipsNotReadableAndNotWritableProperties(): void
18041816
],
18051817
400 => ['description' => 'Invalid input'],
18061818
404 => ['description' => 'Resource not found'],
1819+
422 => ['description' => 'Unprocessable entity'],
18071820
],
18081821
]),
18091822
],
@@ -2263,6 +2276,7 @@ public function testNormalizeWithNestedNormalizationGroups(): void
22632276
],
22642277
400 => ['description' => 'Invalid input'],
22652278
404 => ['description' => 'Resource not found'],
2279+
422 => ['description' => 'Unprocessable entity'],
22662280
],
22672281
]),
22682282
],
@@ -2313,6 +2327,7 @@ public function testNormalizeWithNestedNormalizationGroups(): void
23132327
],
23142328
400 => ['description' => 'Invalid input'],
23152329
404 => ['description' => 'Resource not found'],
2330+
422 => ['description' => 'Unprocessable entity'],
23162331
],
23172332
]),
23182333
],
@@ -3038,6 +3053,7 @@ private function doTestNormalizeWithCustomFormatsDefinedAtOperationLevel(Operati
30383053
],
30393054
400 => ['description' => 'Invalid input'],
30403055
404 => ['description' => 'Resource not found'],
3056+
422 => ['description' => 'Unprocessable entity'],
30413057
],
30423058
]),
30433059
],
@@ -3090,6 +3106,7 @@ private function doTestNormalizeWithCustomFormatsDefinedAtOperationLevel(Operati
30903106
],
30913107
400 => ['description' => 'Invalid input'],
30923108
404 => ['description' => 'Resource not found'],
3109+
422 => ['description' => 'Unprocessable entity'],
30933110
],
30943111
]),
30953112
],
@@ -3248,6 +3265,9 @@ private function doTestNormalizeWithInputAndOutputClass(): void
32483265
404 => [
32493266
'description' => 'Resource not found',
32503267
],
3268+
422 => [
3269+
'description' => 'Unprocessable entity',
3270+
],
32513271
],
32523272
'parameters' => [
32533273
[
@@ -3322,6 +3342,9 @@ private function doTestNormalizeWithInputAndOutputClass(): void
33223342
404 => [
33233343
'description' => 'Resource not found',
33243344
],
3345+
422 => [
3346+
'description' => 'Unprocessable entity',
3347+
],
33253348
],
33263349
]),
33273350
],

tests/Swagger/Serializer/DocumentationNormalizerV3Test.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ private function doTestNormalize(OperationMethodResolverInterface $operationMeth
238238
],
239239
'400' => ['description' => 'Invalid input'],
240240
'404' => ['description' => 'Resource not found'],
241+
'422' => ['description' => 'Unprocessable entity'],
241242
],
242243
]),
243244
],
@@ -297,6 +298,7 @@ private function doTestNormalize(OperationMethodResolverInterface $operationMeth
297298
],
298299
'400' => ['description' => 'Invalid input'],
299300
'404' => ['description' => 'Resource not found'],
301+
'422' => ['description' => 'Unprocessable entity'],
300302
],
301303
]),
302304
],
@@ -372,6 +374,7 @@ private function doTestNormalize(OperationMethodResolverInterface $operationMeth
372374
],
373375
'400' => ['description' => 'Invalid input'],
374376
'404' => ['description' => 'Resource not found'],
377+
'422' => ['description' => 'Unprocessable entity'],
375378
],
376379
]),
377380
],
@@ -867,6 +870,7 @@ public function testNormalizeWithOnlyNormalizationGroups(): void
867870
],
868871
'400' => ['description' => 'Invalid input'],
869872
'404' => ['description' => 'Resource not found'],
873+
'422' => ['description' => 'Unprocessable entity'],
870874
],
871875
]),
872876
],
@@ -926,6 +930,7 @@ public function testNormalizeWithOnlyNormalizationGroups(): void
926930
],
927931
'400' => ['description' => 'Invalid input'],
928932
'404' => ['description' => 'Resource not found'],
933+
'422' => ['description' => 'Unprocessable entity'],
929934
],
930935
]),
931936
],
@@ -1212,6 +1217,7 @@ public function testNormalizeWithOnlyDenormalizationGroups(): void
12121217
],
12131218
'400' => ['description' => 'Invalid input'],
12141219
'404' => ['description' => 'Resource not found'],
1220+
'422' => ['description' => 'Unprocessable entity'],
12151221
],
12161222
]),
12171223
],
@@ -1269,6 +1275,7 @@ public function testNormalizeWithOnlyDenormalizationGroups(): void
12691275
],
12701276
'400' => ['description' => 'Invalid input'],
12711277
'404' => ['description' => 'Resource not found'],
1278+
'422' => ['description' => 'Unprocessable entity'],
12721279
],
12731280
]),
12741281
],
@@ -1440,6 +1447,7 @@ public function testNormalizeWithNormalizationAndDenormalizationGroups(): void
14401447
],
14411448
'400' => ['description' => 'Invalid input'],
14421449
'404' => ['description' => 'Resource not found'],
1450+
'422' => ['description' => 'Unprocessable entity'],
14431451
],
14441452
]),
14451453
],
@@ -1497,6 +1505,7 @@ public function testNormalizeWithNormalizationAndDenormalizationGroups(): void
14971505
],
14981506
'400' => ['description' => 'Invalid input'],
14991507
'404' => ['description' => 'Resource not found'],
1508+
'422' => ['description' => 'Unprocessable entity'],
15001509
],
15011510
]),
15021511
],
@@ -1990,6 +1999,7 @@ public function testNormalizeWithNestedNormalizationGroups(): void
19901999
],
19912000
'400' => ['description' => 'Invalid input'],
19922001
'404' => ['description' => 'Resource not found'],
2002+
'422' => ['description' => 'Unprocessable entity'],
19932003
],
19942004
]),
19952005
],
@@ -2047,6 +2057,7 @@ public function testNormalizeWithNestedNormalizationGroups(): void
20472057
],
20482058
'400' => ['description' => 'Invalid input'],
20492059
'404' => ['description' => 'Resource not found'],
2060+
'422' => ['description' => 'Unprocessable entity'],
20502061
],
20512062
]),
20522063
],
@@ -3119,6 +3130,7 @@ private function doTestNormalizeWithCustomFormatsDefinedAtOperationLevel(Operati
31193130
],
31203131
400 => ['description' => 'Invalid input'],
31213132
404 => ['description' => 'Resource not found'],
3133+
422 => ['description' => 'Unprocessable entity'],
31223134
],
31233135
]),
31243136
],
@@ -3184,6 +3196,7 @@ private function doTestNormalizeWithCustomFormatsDefinedAtOperationLevel(Operati
31843196
],
31853197
400 => ['description' => 'Invalid input'],
31863198
404 => ['description' => 'Resource not found'],
3199+
422 => ['description' => 'Unprocessable entity'],
31873200
],
31883201
]),
31893202
],

0 commit comments

Comments
 (0)