Skip to content

Commit 6bcdd70

Browse files
committed
Prep for publish
1 parent 0256982 commit 6bcdd70

File tree

3 files changed

+106
-2
lines changed

3 files changed

+106
-2
lines changed

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2022 Shalvah
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Scribe
2+
3+
4+
This package provides a [Rector](https://github.com/rectorphp/rector) rule to automatically convert most Scribe v3 docblock tags to v4 PHP 8 attributes.
5+
6+
This package will smartly transform the following tags to their attribute equivalents:
7+
8+
- `header`
9+
- `urlParam`, `queryParam`, and `bodyParam`
10+
- `responseField`
11+
- `response`
12+
- `responseFile`
13+
- `apiResource`,`apiResourceCollection`, and `apiResourceModel`
14+
- `transformer`, `transformerCollection`, and `transformerModel`
15+
- `subgroup`
16+
- `authenticated` and `unauthenticated`
17+
18+
It won't transform `@group` tags or endpoint titles and descriptions (because they can look ugly as attributes).
19+
20+
Example:
21+
22+
```diff
23+
/*
24+
* Do a thing.
25+
*
26+
* Because you want to.
27+
*
28+
* @group Endpoints for doing things
29+
- * @subgroup Getting started
30+
- * @subgroupDescription Get started doing stuff
31+
- * @header Test Value
32+
- * @response 204 scenario="Nothing to see here"
33+
- * @apiResourceCollection App\Http\Resources\UserResource
34+
- * @apiResourceModel App\Models\User with=sideProjects,friends states=admin paginate=12,simple
35+
- * @responseFile 404 scenario="User not found" responses/not_found.json {"resource": "user"}
36+
*/
37+
+ #[Subgroup('Getting started', 'Get started doing stuff')]
38+
+ #[Header('Test', 'Value')]
39+
+ #[Response(status: 204, description: '204, Nothing to see here')]
40+
+ #[ResponseFromApiResource('App\Http\Resources\UserResource', 'App\Models\User', collection: true, factoryStates: ['admin'], with: ['sideProjects', 'friends'], simplePaginate: 12)]
41+
+ #[ResponseFromFile('responses/not_found.json', status: 404, merge: '{"resource": "user"}', description: '404, User not found')]
42+
public function doSomething()
43+
```
44+
45+
## Usage
46+
- Make sure the minimum PHP version in your `composer.json` is 8.0 (ie you should have `"php": ">= 8.0"` or similar in your `"require"` section).
47+
- Install this package
48+
```sh
49+
composer require knuckleswtf/scribe-tags2attributes --dev
50+
```
51+
52+
- Create a `rector.php` file in the root of your project
53+
```sh
54+
./vendor/bin/rector init
55+
```
56+
57+
- Put this in the generated `rector.php` (delete whatever's in it):
58+
```php
59+
<?php
60+
61+
use Rector\Config\RectorConfig;
62+
63+
return static function (RectorConfig $rectorConfig): void {
64+
$rectorConfig->disableParallel();
65+
$rectorConfig->paths([
66+
__DIR__ . '/app/Http/Controllers', // <- replace this with wherever your controllers are
67+
]);
68+
$rectorConfig->importNames();
69+
$rectorConfig->rule(Knuckles\Scribe\Docblock2Attributes\RectorRule::class);
70+
};
71+
```
72+
73+
- Do a dry run. This will tell Rector to print out the changes that will be made, without actually making them. That way you can inspect and verify that it looks okay. We also recommend doing a `git commit`.
74+
```sh
75+
./vendor/bin/rector process --dry-run --clear-cache
76+
```
77+
78+
- When you're ready, run the command.
79+
```sh
80+
./vendor/bin/rector process --clear-cache
81+
```
82+
83+
All done! You can delete the `rector.php` file and run `composer remove knuckleswtf/scribe-tags2attributes`.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "knuckleswtf/scribe-tag2attributes",
2+
"name": "knuckleswtf/scribe-tags2attributes",
33
"license": "MIT",
4-
"description": "Automatically convert Scribe v3 docblock tags to PHP 8 attributes",
4+
"description": "Automatically convert most Scribe v3 docblock tags to v4 PHP 8 attributes",
55
"keywords": [
66
"API",
77
"documentation",

0 commit comments

Comments
 (0)