Skip to content

Commit

Permalink
Merge 2be8d1b into e7bde8f
Browse files Browse the repository at this point in the history
  • Loading branch information
monteiro committed Feb 19, 2021
2 parents e7bde8f + 2be8d1b commit f98f271
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

# 2.6.4

* OpenApi: Fix missing 422 responses in the documentation (#4086)

## 2.6.3

* Identifiers: Re-allow `POST` operations even if no identifier is defined (#4052)
Expand Down
2 changes: 2 additions & 0 deletions src/OpenApi/Factory/OpenApiFactory.php
Expand Up @@ -204,6 +204,7 @@ private function collectPaths(ResourceMetadata $resourceMetadata, string $resour
$successStatus = (string) $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'status', '201');
$responses[$successStatus] = new Model\Response(sprintf('%s resource created', $resourceShortName), $responseContent, null, $responseLinks);
$responses['400'] = new Model\Response('Invalid input');
$responses['422'] = new Model\Response('Unprocessable entity');
break;
case 'PATCH':
case 'PUT':
Expand All @@ -212,6 +213,7 @@ private function collectPaths(ResourceMetadata $resourceMetadata, string $resour
$responseContent = $this->buildContent($responseMimeTypes, $operationOutputSchemas);
$responses[$successStatus] = new Model\Response(sprintf('%s resource updated', $resourceShortName), $responseContent, null, $responseLinks);
$responses['400'] = new Model\Response('Invalid input');
$responses['422'] = new Model\Response('Unprocessable entity');
break;
case 'DELETE':
$successStatus = (string) $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'status', '204');
Expand Down
2 changes: 2 additions & 0 deletions src/Swagger/Serializer/DocumentationNormalizer.php
Expand Up @@ -526,6 +526,7 @@ private function updatePostOperation(bool $v3, \ArrayObject $pathOperation, arra
(string) $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'status', '201') => $successResponse,
'400' => ['description' => 'Invalid input'],
'404' => ['description' => 'Resource not found'],
'422' => ['description' => 'Unprocessable entity'],
];

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

return $this->addRequestBody($v3, $pathOperation, $definitions, $resourceClass, $resourceShortName, $operationType, $operationName, $requestMimeTypes, true);
Expand Down
3 changes: 3 additions & 0 deletions tests/OpenApi/Factory/OpenApiFactoryTest.php
Expand Up @@ -317,6 +317,7 @@ public function testInvoke(): void
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}`.')])
),
'400' => new Model\Response('Invalid input'),
'422' => new Model\Response('Unprocessable entity'),
],
'Creates a Dummy resource.',
'Creates a Dummy resource.',
Expand Down Expand Up @@ -368,6 +369,7 @@ public function testInvoke(): void
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}`.')])
),
'400' => new Model\Response('Invalid input'),
'422' => new Model\Response('Unprocessable entity'),
'404' => new Model\Response('Resource not found'),
],
'Replaces the Dummy resource.',
Expand Down Expand Up @@ -437,6 +439,7 @@ public function testInvoke(): void
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}`.')])
),
'400' => new Model\Response('Invalid input'),
'422' => new Model\Response('Unprocessable entity'),
'404' => new Model\Response('Resource not found'),
],
'Replaces the Dummy resource.',
Expand Down
23 changes: 23 additions & 0 deletions tests/Swagger/Serializer/DocumentationNormalizerV2Test.php
Expand Up @@ -241,6 +241,7 @@ private function doTestNormalize(OperationMethodResolverInterface $operationMeth
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -293,6 +294,7 @@ private function doTestNormalize(OperationMethodResolverInterface $operationMeth
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -349,6 +351,7 @@ private function doTestNormalize(OperationMethodResolverInterface $operationMeth
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -791,6 +794,7 @@ public function testNormalizeWithOnlyNormalizationGroups(): void
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -841,6 +845,7 @@ public function testNormalizeWithOnlyNormalizationGroups(): void
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -1013,6 +1018,7 @@ public function testNormalizeNotAddExtraBodyParameters(): void
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -1063,6 +1069,7 @@ public function testNormalizeNotAddExtraBodyParameters(): void
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -1333,6 +1340,7 @@ public function testNormalizeWithOnlyDenormalizationGroups(): void
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -1383,6 +1391,7 @@ public function testNormalizeWithOnlyDenormalizationGroups(): void
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -1543,6 +1552,7 @@ public function testNormalizeWithNormalizationAndDenormalizationGroups(): void
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -1593,6 +1603,7 @@ public function testNormalizeWithNormalizationAndDenormalizationGroups(): void
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -1752,6 +1763,7 @@ public function testNormalizeSkipsNotReadableAndNotWritableProperties(): void
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -1804,6 +1816,7 @@ public function testNormalizeSkipsNotReadableAndNotWritableProperties(): void
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -2263,6 +2276,7 @@ public function testNormalizeWithNestedNormalizationGroups(): void
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -2313,6 +2327,7 @@ public function testNormalizeWithNestedNormalizationGroups(): void
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -3038,6 +3053,7 @@ private function doTestNormalizeWithCustomFormatsDefinedAtOperationLevel(Operati
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -3090,6 +3106,7 @@ private function doTestNormalizeWithCustomFormatsDefinedAtOperationLevel(Operati
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -3248,6 +3265,9 @@ private function doTestNormalizeWithInputAndOutputClass(): void
404 => [
'description' => 'Resource not found',
],
422 => [
'description' => 'Unprocessable entity'
],
],
'parameters' => [
[
Expand Down Expand Up @@ -3322,6 +3342,9 @@ private function doTestNormalizeWithInputAndOutputClass(): void
404 => [
'description' => 'Resource not found',
],
422 => [
'description' => 'Unprocessable entity'
],
],
]),
],
Expand Down
13 changes: 13 additions & 0 deletions tests/Swagger/Serializer/DocumentationNormalizerV3Test.php
Expand Up @@ -238,6 +238,7 @@ private function doTestNormalize(OperationMethodResolverInterface $operationMeth
],
'400' => ['description' => 'Invalid input'],
'404' => ['description' => 'Resource not found'],
'422' => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -297,6 +298,7 @@ private function doTestNormalize(OperationMethodResolverInterface $operationMeth
],
'400' => ['description' => 'Invalid input'],
'404' => ['description' => 'Resource not found'],
'422' => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -372,6 +374,7 @@ private function doTestNormalize(OperationMethodResolverInterface $operationMeth
],
'400' => ['description' => 'Invalid input'],
'404' => ['description' => 'Resource not found'],
'422' => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -867,6 +870,7 @@ public function testNormalizeWithOnlyNormalizationGroups(): void
],
'400' => ['description' => 'Invalid input'],
'404' => ['description' => 'Resource not found'],
'422' => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -926,6 +930,7 @@ public function testNormalizeWithOnlyNormalizationGroups(): void
],
'400' => ['description' => 'Invalid input'],
'404' => ['description' => 'Resource not found'],
'422' => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -1212,6 +1217,7 @@ public function testNormalizeWithOnlyDenormalizationGroups(): void
],
'400' => ['description' => 'Invalid input'],
'404' => ['description' => 'Resource not found'],
'422' => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -1269,6 +1275,7 @@ public function testNormalizeWithOnlyDenormalizationGroups(): void
],
'400' => ['description' => 'Invalid input'],
'404' => ['description' => 'Resource not found'],
'422' => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -1440,6 +1447,7 @@ public function testNormalizeWithNormalizationAndDenormalizationGroups(): void
],
'400' => ['description' => 'Invalid input'],
'404' => ['description' => 'Resource not found'],
'422' => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -1497,6 +1505,7 @@ public function testNormalizeWithNormalizationAndDenormalizationGroups(): void
],
'400' => ['description' => 'Invalid input'],
'404' => ['description' => 'Resource not found'],
'422' => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -1990,6 +1999,7 @@ public function testNormalizeWithNestedNormalizationGroups(): void
],
'400' => ['description' => 'Invalid input'],
'404' => ['description' => 'Resource not found'],
'422' => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -2047,6 +2057,7 @@ public function testNormalizeWithNestedNormalizationGroups(): void
],
'400' => ['description' => 'Invalid input'],
'404' => ['description' => 'Resource not found'],
'422' => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -3119,6 +3130,7 @@ private function doTestNormalizeWithCustomFormatsDefinedAtOperationLevel(Operati
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down Expand Up @@ -3184,6 +3196,7 @@ private function doTestNormalizeWithCustomFormatsDefinedAtOperationLevel(Operati
],
400 => ['description' => 'Invalid input'],
404 => ['description' => 'Resource not found'],
422 => ['description' => 'Unprocessable entity'],
],
]),
],
Expand Down

0 comments on commit f98f271

Please sign in to comment.