Skip to content

Commit

Permalink
Merge pull request #394 from dedoc/fix/parameters-placement-duplication
Browse files Browse the repository at this point in the history
Added `@ignoreParam` support for skipping a parameter from being documented
  • Loading branch information
romalytvynenko authored May 23, 2024
2 parents dbbf57b + 516fb08 commit 24a27c9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Support/Generator/Types/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class Type
{
use WithAttributes;

protected string $type;
public string $type;

public string $format = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public function __construct(string $name, $rules, ?PhpDocNode $docNode, TypeTran

public function generate()
{
if (count($this->docNode?->getTagsByName('@ignoreParam') ?? [])) {
return null;
}

$rules = collect($this->rules)
->map(fn ($v) => method_exists($v, '__toString') ? $v->__toString() : $v)
->sortByDesc($this->rulesSorter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function handle()
{
return collect($this->rules)
->map(fn ($rules, $name) => (new RulesToParameter($name, $rules, $this->nodeDocs[$name] ?? null, $this->openApiTransformer))->generate())
->filter()
->pipe($this->handleNested(...))
->pipe($this->handleConfirmed(...))
->values()
Expand Down
20 changes: 20 additions & 0 deletions tests/Support/OperationExtensions/RequestBodyExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,23 @@ public function index(Illuminate\Http\Request $request)
]);
}
}

it('ignores param in rules with annotation', function () {
$openApiDocument = generateForRoute(function () {
return RouteFacade::get('api/test/{id}', [RequestBodyExtensionTest__ignores_rules_param_with_annotation::class, 'index']);
});

expect($params = $openApiDocument['paths']['/test/{id}']['get']['parameters'])
->toHaveCount(1)
->and($params[0]['in'])->toBe('path');
});
class RequestBodyExtensionTest__ignores_rules_param_with_annotation
{
public function index(Illuminate\Http\Request $request, string $id)
{
$request->validate([
/** @ignoreParam */
'id' => 'integer',
]);
}
}

0 comments on commit 24a27c9

Please sign in to comment.