Skip to content

Commit

Permalink
Add enum specification on order filter API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericbarthelet committed Aug 10, 2019
1 parent 92f655c commit 087d53f
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Bridge/Doctrine/Common/Filter/OrderFilterTrait.php
Expand Up @@ -52,6 +52,13 @@ public function getDescription(string $resourceClass): array
'property' => $propertyName,
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
strtolower(OrderFilterInterface::DIRECTION_ASC),
strtolower(OrderFilterInterface::DIRECTION_DESC),
],
],
];
}

Expand Down
4 changes: 4 additions & 0 deletions src/Swagger/Serializer/DocumentationNormalizer.php
Expand Up @@ -841,6 +841,10 @@ private function getFiltersParameters(bool $v3, string $resourceClass, string $o
$type = $this->getType($v3, $data['type'], $data['is_collection'] ?? false, null, null, $definitions, $serializerContext);
$v3 ? $parameter['schema'] = $type : $parameter += $type;

if ($v3 && isset($data['schema'])) {
$parameter['schema'] = $data['schema'];
}

if ('array' === $type['type'] ?? '') {
$deepObject = \in_array($data['type'], [Type::BUILTIN_TYPE_ARRAY, Type::BUILTIN_TYPE_OBJECT], true);

Expand Down
14 changes: 14 additions & 0 deletions tests/Bridge/Doctrine/Common/Filter/OrderFilterTestTrait.php
Expand Up @@ -28,11 +28,25 @@ public function testGetDescription()
'property' => 'id',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[name]' => [
'property' => 'name',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
], $filter->getDescription($this->resourceClass));
}
Expand Down
112 changes: 112 additions & 0 deletions tests/Bridge/Doctrine/MongoDbOdm/Filter/OrderFilterTest.php
Expand Up @@ -39,81 +39,193 @@ public function testGetDescriptionDefaultFields()
'property' => 'id',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[name]' => [
'property' => 'name',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[alias]' => [
'property' => 'alias',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[description]' => [
'property' => 'description',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[dummy]' => [
'property' => 'dummy',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[dummyDate]' => [
'property' => 'dummyDate',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[dummyFloat]' => [
'property' => 'dummyFloat',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[dummyPrice]' => [
'property' => 'dummyPrice',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[jsonData]' => [
'property' => 'jsonData',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[arrayData]' => [
'property' => 'arrayData',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[name_converted]' => [
'property' => 'name_converted',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[dummyBoolean]' => [
'property' => 'dummyBoolean',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[relatedDummy]' => [
'property' => 'relatedDummy',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[relatedDummies]' => [
'property' => 'relatedDummies',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[relatedOwnedDummy]' => [
'property' => 'relatedOwnedDummy',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[relatedOwningDummy]' => [
'property' => 'relatedOwningDummy',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
], $filter->getDescription($this->resourceClass));
}
Expand Down
84 changes: 84 additions & 0 deletions tests/Bridge/Doctrine/Orm/Filter/OrderFilterTest.php
Expand Up @@ -40,61 +40,145 @@ public function testGetDescriptionDefaultFields()
'property' => 'id',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[name]' => [
'property' => 'name',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[alias]' => [
'property' => 'alias',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[description]' => [
'property' => 'description',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[dummy]' => [
'property' => 'dummy',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[dummyDate]' => [
'property' => 'dummyDate',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[dummyFloat]' => [
'property' => 'dummyFloat',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[dummyPrice]' => [
'property' => 'dummyPrice',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[jsonData]' => [
'property' => 'jsonData',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[arrayData]' => [
'property' => 'arrayData',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[name_converted]' => [
'property' => 'name_converted',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
'order[dummyBoolean]' => [
'property' => 'dummyBoolean',
'type' => 'string',
'required' => false,
'schema' => [
'type' => 'string',
'enum' => [
'asc',
'desc',
],
],
],
], $filter->getDescription($this->resourceClass));
}
Expand Down

0 comments on commit 087d53f

Please sign in to comment.