Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added @ignoreParam support for skipping a parameter from being documented #394

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
]);
}
}
Loading