123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717 |
- <?php
- namespace Knuckles\Scribe\Tests\Fixtures;
- use Illuminate\Http\Request;
- use Illuminate\Routing\Controller;
- use Illuminate\Validation\Rule;
- use Knuckles\Scribe\Tools\Utils;
- /**
- * @group Group A
- */
- class TestController extends Controller
- {
- public function dummy()
- {
- return '';
- }
- /**
- * Example title.
- * This will be the long description.
- * It can also be multiple lines long.
- */
- public function withEndpointDescription()
- {
- return '';
- }
- /**
- * @group Group B
- */
- public function withGroupOverride()
- {
- return 'Group B, baby!';
- }
- /**
- * This is also in Group B. No route description. Route title before gropp.
- *
- * @group Group B
- */
- public function withGroupOverride2()
- {
- return '';
- }
- /**
- * @group Group B
- *
- * This is also in Group B. Route title after group.
- */
- public function withGroupOverride3()
- {
- return '';
- }
- /**
- * This is in Group C. Route title before group.
- *
- * @group Group C
- *
- * Group description after group.
- */
- public function withGroupOverride4()
- {
- return '';
- }
- /**
- * Endpoint with body parameters.
- *
- * @bodyParam user_id int required The id of the user. Example: 9
- * @bodyParam room_id string The id of the room.
- * @bodyParam forever boolean Whether to ban the user forever. Example: false
- * @bodyParam another_one number Just need something here.
- * @bodyParam yet_another_param object required Some object params.
- * @bodyParam yet_another_param.name string required
- * @bodyParam even_more_param number[] A list of numbers
- * @bodyParam book object
- * @bodyParam book.name string
- * @bodyParam book.author_id integer
- * @bodyParam book.pages_count integer
- * @bodyParam ids int[]
- * @bodyParam users object[]
- * @bodyParam users[].first_name string required The first name of the user. Example: John
- * @bodyParam users[].last_name string required The last name of the user. Example: Doe
- */
- public function withBodyParameters()
- {
- return '';
- }
- /**
- * Endpoint with body form data parameters.
- *
- * @bodyParam name string required Name of image. Example: cat.jpg
- * @bodyParam image file required The image. Example: config/scribe.php
- */
- public function withFormDataParams()
- {
- request()->validate(['image' => 'file|required']);
- return [
- 'filename' => request()->file('image')->getFilename(),
- 'filepath' => request()->file('image')->getPath(),
- 'name' => request('name'),
- ];
- }
- /**
- * Endpoint with body parameters as array.
- *
- * @bodyParam [] object[] Details.
- * @bodyParam [].first_name string required The first name of the user. Example: John
- * @bodyParam [].last_name string required The last name of the user. Example: Doe
- * @bodyParam [].contacts object[] required Contact info
- * @bodyParam [].contacts[].first_name string required The first name of the contact. Example: Janelle
- * @bodyParam [].contacts[].last_name string required The last name of the contact. Example: Monáe
- * @bodyParam [].roles string[] required The name of the role. Example: ["Admin"]
- */
- public function withBodyParametersAsArray()
- {
- return '';
- }
- public function withFormRequestParameter(string $test, TestRequest $request)
- {
- return '';
- }
- public function withFormRequestParameterQueryParams(string $test, TestRequestQueryParams $request)
- {
- return '';
- }
- public function withFormRequestParameterQueryParamsComment(string $test, TestRequestQueryParamsComment $request)
- {
- return '';
- }
- /**
- * @bodyParam direct_one string Is found directly on the method.
- */
- public function withNonCommentedFormRequestParameter(TestNonCommentedRequest $request)
- {
- return '';
- }
- /**
- * @queryParam location_id required The id of the location.
- * @queryParam user_id required The id of the user. Example: me
- * @queryParam page required The page number. Example: 4
- * @queryParam filters The filters.
- * @queryParam url_encoded Used for testing that URL parameters will be URL-encoded where needed. Example: + []&=
- */
- public function withQueryParameters()
- {
- return '';
- }
- /**
- * @bodyParam included string required Exists in examples. Example: 'Here'
- * @bodyParam excluded_body_param int Does not exist in examples. No-example
- * @queryParam excluded_query_param Does not exist in examples. No-example
- */
- public function withExcludedExamples()
- {
- return '';
- }
- /**
- * @authenticated
- * @responseField user_id string The ID of the newly created user
- * @responseField creator_id string The ID of the creator
- */
- public function withAuthenticatedTag()
- {
- return '';
- }
- /**
- * @responseField user_id string The ID of the newly created user
- * @responseField creator_id string The ID of the creator
- */
- public function withResponseFieldTag()
- {
- return '';
- }
- /**
- * @apiResource \Knuckles\Scribe\Tests\Fixtures\TestUserApiResource
- * @apiResourceModel \Knuckles\Scribe\Tests\Fixtures\TestUser
- */
- public function withEloquentApiResource()
- {
- return new TestUserApiResource(Utils::getModelFactory(TestUser::class)->make(['id' => 0]));
- }
- /**
- * @apiResource \Knuckles\Scribe\Tests\Fixtures\TestEmptyApiResource
- */
- public function withEmptyApiResource()
- {
- return new TestEmptyApiResource();
- }
- /**
- * @group Other😎
- *
- * @apiResourceCollection Knuckles\Scribe\Tests\Fixtures\TestUserApiResource
- * @apiResourceModel Knuckles\Scribe\Tests\Fixtures\TestUser
- */
- public function withEloquentApiResourceCollection()
- {
- return TestUserApiResource::collection(
- collect([Utils::getModelFactory(TestUser::class)->make(['id' => 0])])
- );
- }
- /**
- * @group Other😎
- *
- * @apiResourceCollection Knuckles\Scribe\Tests\Fixtures\TestUserApiResourceCollection
- * @apiResourceModel Knuckles\Scribe\Tests\Fixtures\TestUser
- */
- public function withEloquentApiResourceCollectionClass()
- {
- return new TestUserApiResourceCollection(
- collect([Utils::getModelFactory(TestUser::class)->make(['id' => 0])])
- );
- }
- public function checkCustomHeaders(Request $request)
- {
- return $request->headers->all();
- }
- public function shouldFetchRouteResponse()
- {
- $fruit = new \stdClass();
- $fruit->id = 4;
- $fruit->name = ' banana ';
- $fruit->color = 'RED';
- $fruit->weight = 1;
- $fruit->delicious = true;
- return [
- 'id' => (int) $fruit->id,
- 'name' => trim($fruit->name),
- 'color' => strtolower($fruit->color),
- 'weight' => $fruit->weight . ' kg',
- 'delicious' => $fruit->delicious,
- 'responseCall' => true,
- ];
- }
- public function echoesConfig()
- {
- return [
- 'app.env' => config('app.env'),
- ];
- }
- /**
- * @group Other😎
- *
- * @urlParam param required Example: 4
- * @urlParam param2 required
- * @urlParam param4 No-example.
- *
- * @queryParam something
- */
- public function echoesUrlParameters($param, $param2, $param3 = null, $param4 = null)
- {
- return compact('param', 'param2', 'param3', 'param4');
- }
- /**
- * @authenticated
- * @urlparam id Example: 3
- */
- public function echoesRequestValues($id)
- {
- return [
- '{id}' => $id,
- 'header' => request()->header('header'),
- 'auth' => request()->header('Authorization'),
- 'queryParam' => request()->query('queryParam'),
- 'bodyParam' => request()->get('bodyParam'),
- ];
- }
- /**
- * @response {
- * "result": "Лорем ипсум долор сит амет"
- * }
- */
- public function withUtf8ResponseTag()
- {
- return ['result' => 'Лорем ипсум долор сит амет'];
- }
- /**
- * @hideFromAPIDocumentation
- */
- public function skip()
- {
- }
- /**
- * @response {
- * "id": 4,
- * "name": "banana",
- * "color": "red",
- * "weight": "1 kg",
- * "delicious": true,
- * "responseTag": true
- * }
- */
- public function withResponseTag()
- {
- return '';
- }
- /**
- * @response 422 {
- * "message": "Validation error"
- * }
- */
- public function withResponseTagAndStatusCode()
- {
- return '';
- }
- /**
- * @response {
- * "id": 4,
- * "name": "banana",
- * "color": "red",
- * "weight": "1 kg",
- * "delicious": true,
- * "multipleResponseTagsAndStatusCodes": true
- * }
- * @response 401 {
- * "message": "Unauthorized"
- * }
- */
- public function withMultipleResponseTagsAndStatusCode()
- {
- return '';
- }
- /**
- * @transformer \Knuckles\Scribe\Tests\Fixtures\TestTransformer
- */
- public function transformerTag()
- {
- return '';
- }
- /**
- * @transformer 201 \Knuckles\Scribe\Tests\Fixtures\TestTransformer
- */
- public function transformerTagWithStatusCode()
- {
- return '';
- }
- /**
- * @transformer \Knuckles\Scribe\Tests\Fixtures\TestTransformer
- * @transformermodel \Knuckles\Scribe\Tests\Fixtures\TestModel
- */
- public function transformerTagWithModel()
- {
- return '';
- }
- /**
- * @transformercollection \Knuckles\Scribe\Tests\Fixtures\TestTransformer
- */
- public function transformerCollectionTag()
- {
- return '';
- }
- /**
- * @transformercollection \Knuckles\Scribe\Tests\Fixtures\TestTransformer
- * @transformermodel \Knuckles\Scribe\Tests\Fixtures\TestModel
- */
- public function transformerCollectionTagWithModel()
- {
- return '';
- }
- /**
- * @responseFile response_test.json
- */
- public function responseFileTag()
- {
- return '';
- }
- /**
- * @responseFile response_test.json
- * @responseFile 401 response_error_test.json
- */
- public function withResponseFileTagAndStatusCode()
- {
- return '';
- }
- /**
- * @responseFile response_test.json {"message" : "Serendipity"}
- */
- public function responseFileTagAndCustomJson()
- {
- return '';
- }
- /**
- * @responseFile i-do-not-exist.json
- */
- public function withNonExistentResponseFile()
- {
- return '';
- }
- public function withInlineRequestValidate(Request $request)
- {
- // Some stuff
- $validated = $request->validate([
- // The id of the user. Example: 9
- 'user_id' => 'int|required',
- // The id of the room.
- 'room_id' => ['string', 'in:3,5,6'],
- // Whether to ban the user forever. Example: false
- 'forever' => 'boolean',
- // Just need something here. No-example
- 'another_one' => 'numeric',
- 'even_more_param' => 'array',
- 'book.name' => 'string',
- 'book.author_id' => 'integer',
- 'book.pages_count' => 'integer',
- 'ids.*' => 'integer',
- // The first name of the user. Example: John
- 'users.*.first_name' => ['string'],
- // The last name of the user. Example: Doe
- 'users.*.last_name' => 'string',
- ]);
- // Do stuff
- }
- public function withInlineRequestValidateNoAssignment(Request $request)
- {
- $request->validate([
- // The id of the user. Example: 9
- 'user_id' => 'int|required',
- // The id of the room.
- 'room_id' => ['string', 'in:3,5,6'],
- // Whether to ban the user forever. Example: false
- 'forever' => 'boolean',
- // Just need something here. No-example
- 'another_one' => 'numeric',
- 'even_more_param' => 'array',
- 'book.name' => 'string',
- 'book.author_id' => 'integer',
- 'book.pages_count' => 'integer',
- 'ids.*' => 'integer',
- // The first name of the user. Example: John
- 'users.*.first_name' => ['string'],
- // The last name of the user. Example: Doe
- 'users.*.last_name' => 'string',
- ]);
- // Do stuff
- }
- public function withInlineRequestValidateQueryParams(Request $request)
- {
- // Query parameters
- $validated = $request->validate([
- // The id of the user. Example: 9
- 'user_id' => 'int|required',
- // The id of the room.
- 'room_id' => ['string', 'in:3,5,6'],
- // Whether to ban the user forever. Example: false
- 'forever' => 'boolean',
- // Just need something here. No-example
- 'another_one' => 'numeric',
- 'even_more_param' => 'array',
- 'book.name' => 'string',
- 'book.author_id' => 'integer',
- 'book.pages_count' => 'integer',
- 'ids.*' => 'integer',
- // The first name of the user. Example: John
- 'users.*.first_name' => ['string'],
- // The last name of the user. Example: Doe
- 'users.*.last_name' => 'string',
- ]);
- // Do stuff
- }
- public function withInlineRequestValidateFacade()
- {
- // Some stuff
- $validated = Request::validate([
- // The id of the user. Example: 9
- 'user_id' => 'int|required',
- // The id of the room.
- 'room_id' => ['string', 'in:3,5,6'],
- // Whether to ban the user forever. Example: false
- 'forever' => 'boolean',
- // Just need something here. No-example
- 'another_one' => 'numeric',
- 'even_more_param' => 'array',
- 'book.name' => 'string',
- 'book.author_id' => 'integer',
- 'book.pages_count' => 'integer',
- 'ids.*' => 'integer',
- // The first name of the user. Example: John
- 'users.*.first_name' => ['string'],
- // The last name of the user. Example: Doe
- 'users.*.last_name' => 'string',
- ]);
- // Do stuff
- }
- public function withInlineRequestValidateFacadeNoAssignment()
- {
- Request::validate([
- // The id of the user. Example: 9
- 'user_id' => 'int|required',
- // The id of the room.
- 'room_id' => ['string', 'in:3,5,6'],
- // Whether to ban the user forever. Example: false
- 'forever' => 'boolean',
- // Just need something here. No-example
- 'another_one' => 'numeric',
- 'even_more_param' => 'array',
- 'book.name' => 'string',
- 'book.author_id' => 'integer',
- 'book.pages_count' => 'integer',
- 'ids.*' => 'integer',
- // The first name of the user. Example: John
- 'users.*.first_name' => ['string'],
- // The last name of the user. Example: Doe
- 'users.*.last_name' => 'string',
- ]);
- // Do stuff
- }
- public function withInlineRequestValidateFacadeWithFullImport()
- {
- // Some stuff
- $validated = \Illuminate\Support\Facades\Request::validate([
- // The id of the user. Example: 9
- 'user_id' => 'int|required',
- // The id of the room.
- 'room_id' => ['string', 'in:3,5,6'],
- // Whether to ban the user forever. Example: false
- 'forever' => 'boolean',
- // Just need something here. No-example
- 'another_one' => 'numeric',
- 'even_more_param' => 'array',
- 'book.name' => 'string',
- 'book.author_id' => 'integer',
- 'book.pages_count' => 'integer',
- 'ids.*' => 'integer',
- // The first name of the user. Example: John
- 'users.*.first_name' => ['string'],
- // The last name of the user. Example: Doe
- 'users.*.last_name' => 'string',
- ]);
- // Do stuff
- }
- public function withInlineRequestValidateWithBagFacade()
- {
- // Some stuff
- $validated = Request::validateWithBag('stuff', [
- // The id of the user. Example: 9
- 'user_id' => 'int|required',
- // The id of the room.
- 'room_id' => ['string', 'in:3,5,6'],
- // Whether to ban the user forever. Example: false
- 'forever' => 'boolean',
- // Just need something here. No-example
- 'another_one' => 'numeric',
- 'even_more_param' => 'array',
- 'book.name' => 'string',
- 'book.author_id' => 'integer',
- 'book.pages_count' => 'integer',
- 'ids.*' => 'integer',
- // The first name of the user. Example: John
- 'users.*.first_name' => ['string'],
- // The last name of the user. Example: Doe
- 'users.*.last_name' => 'string',
- ]);
- // Do stuff
- }
- public function withInlineValidatorMake(Request $request)
- {
- // Some stuff
- $validator = Validator::make($request, [
- // The id of the user. Example: 9
- 'user_id' => 'int|required',
- // The id of the room.
- 'room_id' => ['string', 'in:3,5,6'],
- // Whether to ban the user forever. Example: false
- 'forever' => 'boolean',
- // Just need something here. No-example
- 'another_one' => 'numeric',
- 'even_more_param' => 'array',
- 'book.name' => 'string',
- 'book.author_id' => 'integer',
- 'book.pages_count' => 'integer',
- 'ids.*' => 'integer',
- // The first name of the user. Example: John
- 'users.*.first_name' => ['string'],
- // The last name of the user. Example: Doe
- 'users.*.last_name' => 'string',
- ]);
- // Do stuff
- if ($validator->fails()) {
- }
- }
- public function withInlineRequestValidateWithBag(Request $request)
- {
- $request->validateWithBag('stuff', [
- // The id of the user. Example: 9
- 'user_id' => 'int|required',
- // The id of the room.
- 'room_id' => ['string', 'in:3,5,6'],
- // Whether to ban the user forever. Example: false
- 'forever' => 'boolean',
- // Just need something here. No-example
- 'another_one' => 'numeric',
- 'even_more_param' => 'array',
- 'book.name' => 'string',
- 'book.author_id' => 'integer',
- 'book.pages_count' => 'integer',
- 'ids.*' => 'integer',
- // The first name of the user. Example: John
- 'users.*.first_name' => ['string'],
- // The last name of the user. Example: Doe
- 'users.*.last_name' => 'string',
- ]);
- // Do stuff
- }
- public function withInlineThisValidate(Request $request)
- {
- $this->validate($request, [
- // The id of the user. Example: 9
- 'user_id' => 'int|required',
- // The id of the room.
- 'room_id' => ['string', 'in:3,5,6'],
- // Whether to ban the user forever. Example: false
- 'forever' => 'boolean',
- // Just need something here. No-example
- 'another_one' => 'numeric',
- 'even_more_param' => 'array',
- 'book.name' => 'string',
- 'book.author_id' => 'integer',
- 'book.pages_count' => 'integer',
- 'ids.*' => 'integer',
- // The first name of the user. Example: John
- 'users.*.first_name' => ['string'],
- // The last name of the user. Example: Doe
- 'users.*.last_name' => 'string',
- ]);
- // Do stuff
- }
- public function withInjectedModel(TestUser $user)
- {
- return null;
- }
- public function withInjectedModelFullParamName(TestPost $testPost)
- {
- return null;
- }
- public function withEnumRule(Request $request)
- {
- $request->validate([
- 'enum_class' => ['required', new Rules\Enum(\Knuckles\Scribe\Tests\Fixtures\TestStringBackedEnum::class), 'nullable'],
- 'enum_string' => ['required', Rule::enum('\Knuckles\Scribe\Tests\Fixtures\TestIntegerBackedEnum'), 'nullable'],
- // Not full path class call won't work
- 'enum_nonexistent' => ['required', new Rules\Enum(TestStringBackedEnum::class)],
- ]);
- }
- public function withInjectedEnumAndModel(Category $category, TestUser $user)
- {
- return null;
- }
- }
- enum Category: string
- {
- case Fruits = 'fruits';
- case People = 'people';
- }
|