Skip to content

Commit 9fe70e7

Browse files
committed
Simplify object notation for single-filter usage (#27)
1 parent c0a2fc7 commit 9fe70e7

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

src/PropertyProcessor/Filter/FilterProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function process(
4343
GeneratorConfiguration $generatorConfiguration,
4444
Schema $schema
4545
): void {
46-
if (is_string($filterList)) {
46+
if (is_string($filterList) || (is_array($filterList) && isset($filterList['filter']))) {
4747
$filterList = [$filterList];
4848
}
4949

tests/Basic/FilterTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,15 @@ public function testFilterExceptionsAreCaught(): void
465465
}
466466

467467
/**
468-
* @dataProvider namespaceDataProvider
468+
* @dataProvider additionalFilterOptionsDataProvider
469469
*
470470
* @param string $namespace
471+
* @param string $schemaFile
471472
*/
472-
public function testAdditionalFilterOptions(string $namespace): void
473+
public function testAdditionalFilterOptions(string $namespace, string $schemaFile): void
473474
{
474475
$className = $this->generateClassFromFile(
475-
'FilterOptions.json',
476+
$schemaFile,
476477
(new GeneratorConfiguration())->setSerialization(true)->setNamespacePrefix($namespace)
477478
);
478479

@@ -486,6 +487,17 @@ public function testAdditionalFilterOptions(string $namespace): void
486487
$this->assertSame(json_encode($expectedSerialization), $object->toJSON());
487488
}
488489

490+
public function additionalFilterOptionsDataProvider(): array
491+
{
492+
return $this->combineDataProvider(
493+
$this->namespaceDataProvider(),
494+
[
495+
'Chain notation' => ['FilterOptionsChainNotation.json'],
496+
'Single filter notation' => ['FilterOptions.json'],
497+
]
498+
);
499+
}
500+
489501
public function testTransformingFilterAppliedToAnArrayPropertyThrowsAnException(): void
490502
{
491503
$this->expectException(SchemaException::class);

tests/Schema/FilterTest/FilterOptions.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
"properties": {
44
"created": {
55
"type": "string",
6-
"filter": [
7-
{
8-
"filter": "dateTime",
9-
"createFromFormat": "!dmY",
10-
"outputFormat": "Ymd"
11-
}
12-
]
6+
"filter": {
7+
"filter": "dateTime",
8+
"createFromFormat": "!dmY",
9+
"outputFormat": "Ymd"
10+
}
1311
}
1412
}
1513
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"created": {
5+
"type": "string",
6+
"filter": [
7+
{
8+
"filter": "dateTime",
9+
"createFromFormat": "!dmY",
10+
"outputFormat": "Ymd"
11+
}
12+
]
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)