|
46 | 46 | description: '' |
47 | 47 | version: 1.0.0 |
48 | 48 | servers: |
49 | | - - |
50 | | - url: 'http://localhost' |
| 49 | + - url: 'http://localhost' |
51 | 50 | tags: |
52 | | - - |
53 | | - name: Endpoints |
| 51 | + - name: Endpoints |
54 | 52 | description: '' |
55 | 53 | paths: |
56 | 54 | /api/health: |
@@ -516,37 +514,23 @@ With descriptions covered, let's properly document the stuff these descriptions |
516 | 514 |
|
517 | 515 | ### Adding tags |
518 | 516 |
|
519 | | -In OpenAPI, `tags` are used to group related operations together. Typically, a good way to use tags is to have one tag per "resource" and then associate all the relevant operations that access and modify that resource together. We'll add a group annotation to the top of the controller. |
| 517 | +In OpenAPI, `tags` are used to group related operations together. Typically, a |
| 518 | +good way to use tags is to have one tag per "resource" and then associate all |
| 519 | +the relevant operations that access and modify that resource together. |
520 | 520 |
|
521 | 521 | ```php |
522 | | -// !focus(1) |
523 | | -#[Group(name: 'Races', description: 'A series of endpoints that allow programatic access to managing F1 races.', authenticated: true)] |
524 | | -final readonly class IndexController |
525 | | -{ |
526 | | - public function __construct( |
527 | | - private AuthManager $auth, |
528 | | - private RaceRepository $repository, |
529 | | - ) { |
530 | | - } |
| 522 | +use Knuckles\Scribe\Attributes\{Authenticated, Group, BodyParam, QueryParam}; |
531 | 523 |
|
532 | | - #[Authenticated] |
533 | | - #[ResponseFromApiResource(RaceResource::class, Race::class, collection: true)] |
534 | | - #[Endpoint(title: 'Browse Races', description: 'Browse through the F1 races for the season.')] |
535 | | - public function __invoke(Request $request): CollectionResponse |
536 | | - { |
537 | | - $races = $this->repository->forSeason( |
538 | | - season: $request->query('season', date('Y')), |
539 | | - ); |
540 | | -
|
541 | | - return new CollectionResponse( |
542 | | - data: RaceResource::collection( |
543 | | - resource: $races->paginate(), |
544 | | - ), |
545 | | - ); |
546 | | - } |
547 | | -} |
| 524 | +#[Group(name: 'Races', description: 'A series of endpoints that allow programmatic access to managing F1 races.')] |
| 525 | +class RaceController extends Controller |
| 526 | +{ |
| 527 | + // ... |
548 | 528 | ``` |
549 | 529 |
|
| 530 | +Now instead of seeing `tags: [Endpoints]` in this controllers endpoints, the tag will be `Races`, and the description will be included in the OpenAPI document as a tag description. |
| 531 | + |
| 532 | +**Learn more about [OpenAPI tags](/openapi/tags).** |
| 533 | + |
550 | 534 | ## Documenting parameters |
551 | 535 |
|
552 | 536 | The whole point of an API is being able to send and receive data, so describing and documenting [API parameters](/api-design/parameters.md) for an endpoint is crucial. OpenAPI supports [several types of parameters](/openapi/requests/parameters), with the most common being `path`, `query`, and `header` parameters. |
|
0 commit comments