Skip to content

Commit 2570c24

Browse files
committed
Allow adding inline documentation
1 parent c6ef714 commit 2570c24

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

src/Handler/Index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ private function filter($query, Request $request)
246246
}
247247

248248
if (isset($filters[$name])) {
249-
$filters[$name]($query, $value, $request);
249+
$filters[$name]->getCallback()($query, $value, $request);
250250
continue;
251251
}
252252

src/Schema/Field.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ abstract class Field
2020
use HasListeners;
2121

2222
private $name;
23+
private $description;
2324
private $property;
2425
private $visible = true;
2526
private $single = false;
@@ -41,6 +42,16 @@ public function __construct(string $name)
4142
*/
4243
abstract public function getLocation(): string;
4344

45+
/**
46+
* Set the description of the field for documentation generation.
47+
*/
48+
public function description(string $description)
49+
{
50+
$this->description = $description;
51+
52+
return $this;
53+
}
54+
4455
/**
4556
* Set the model property to which this field corresponds.
4657
*/

src/Schema/Filter.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* This file is part of tobyz/json-api-server.
5+
*
6+
* (c) Toby Zerner <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Tobyz\JsonApiServer\Schema;
13+
14+
final class Filter
15+
{
16+
private $name;
17+
private $callback;
18+
private $description;
19+
20+
public function __construct(string $name, callable $callback)
21+
{
22+
$this->name = $name;
23+
$this->callback = $callback;
24+
}
25+
26+
public function getName(): string
27+
{
28+
return $this->name;
29+
}
30+
31+
public function getCallback(): callable
32+
{
33+
return $this->callback;
34+
}
35+
36+
/**
37+
* Set the description of the type for documentation generation.
38+
*/
39+
public function description(string $description)
40+
{
41+
$this->description = $description;
42+
}
43+
}

src/Schema/Type.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ final class Type
1919
{
2020
use HasListeners, HasMeta;
2121

22+
private $description;
2223
private $fields = [];
2324
private $filters = [];
2425
private $sortFields = [];
@@ -35,6 +36,14 @@ final class Type
3536
private $deletable = false;
3637
private $deleteCallback;
3738

39+
/**
40+
* Set the description of the type for documentation generation.
41+
*/
42+
public function description(string $description)
43+
{
44+
$this->description = $description;
45+
}
46+
3847
/**
3948
* Add an attribute to the resource type.
4049
*
@@ -98,9 +107,9 @@ public function getFields(): array
98107
/**
99108
* Add a filter to the resource type.
100109
*/
101-
public function filter(string $name, callable $callback): void
110+
public function filter(string $name, callable $callback): Filter
102111
{
103-
$this->filters[$name] = $callback;
112+
return $this->filters[$name] = new Filter($name, $callback);
104113
}
105114

106115
/**

0 commit comments

Comments
 (0)