TestController.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <?php
  2. namespace Knuckles\Scribe\Tests\Fixtures;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Routing\Controller;
  5. use Knuckles\Scribe\Tests\Unit\GeneratorTestCase;
  6. use Knuckles\Scribe\Tools\Utils;
  7. /**
  8. * @group Group A
  9. */
  10. class TestController extends Controller
  11. {
  12. public function dummy()
  13. {
  14. return '';
  15. }
  16. /**
  17. * Example title.
  18. * This will be the long description.
  19. * It can also be multiple lines long.
  20. */
  21. public function withEndpointDescription()
  22. {
  23. return '';
  24. }
  25. /**
  26. * @group Group B
  27. */
  28. public function withGroupOverride()
  29. {
  30. return 'Group B, baby!';
  31. }
  32. /**
  33. * This is also in Group B. No route description. Route title before gropp.
  34. *
  35. * @group Group B
  36. */
  37. public function withGroupOverride2()
  38. {
  39. return '';
  40. }
  41. /**
  42. * @group Group B
  43. *
  44. * This is also in Group B. Route title after group.
  45. */
  46. public function withGroupOverride3()
  47. {
  48. return '';
  49. }
  50. /**
  51. * This is in Group C. Route title before group.
  52. *
  53. * @group Group C
  54. *
  55. * Group description after group.
  56. */
  57. public function withGroupOverride4()
  58. {
  59. return '';
  60. }
  61. /**
  62. * Endpoint with body parameters.
  63. *
  64. * @bodyParam user_id int required The id of the user. Example: 9
  65. * @bodyParam room_id string The id of the room.
  66. * @bodyParam forever boolean Whether to ban the user forever. Example: false
  67. * @bodyParam another_one number Just need something here.
  68. * @bodyParam yet_another_param object required Some object params.
  69. * @bodyParam yet_another_param.name string required Subkey in the object param.
  70. * @bodyParam even_more_param array Some array params.
  71. * @bodyParam even_more_param.* number Subkey in the array param.
  72. * @bodyParam book.name string
  73. * @bodyParam book.author_id integer
  74. * @bodyParam book[pages_count] integer
  75. * @bodyParam ids.* integer
  76. * @bodyParam users.*.first_name string The first name of the user. Example: John
  77. * @bodyParam users.*.last_name string The last name of the user. Example: Doe
  78. */
  79. public function withBodyParameters()
  80. {
  81. return '';
  82. }
  83. /**
  84. * Endpoint with body form data parameters.
  85. *
  86. * @bodyParam name string required Name of image. Example: cat.jpg
  87. * @bodyParam image file required The image.
  88. */
  89. public function withFormDataParams()
  90. {
  91. return '';
  92. }
  93. /**
  94. * Endpoint with body parameters as array.
  95. *
  96. * @bodyParam *.first_name string The first name of the user. Example: John
  97. * @bodyParam *.last_name string The last name of the user. Example: Doe
  98. * @bodyParam *.contacts.*.first_name string The first name of the contact. Example: John
  99. * @bodyParam *.contacts.*.last_name string The last name of the contact. Example: Doe
  100. * @bodyParam *.roles.* string The name of the role. Example: Admin
  101. */
  102. public function withBodyParametersAsArray()
  103. {
  104. return '';
  105. }
  106. public function withFormRequestParameter(string $test, TestRequest $request)
  107. {
  108. return '';
  109. }
  110. /**
  111. * @bodyParam direct_one string Is found directly on the method.
  112. */
  113. public function withNonCommentedFormRequestParameter(TestNonCommentedRequest $request)
  114. {
  115. return '';
  116. }
  117. /**
  118. * @queryParam location_id required The id of the location.
  119. * @queryParam user_id required The id of the user. Example: me
  120. * @queryParam page required The page number. Example: 4
  121. * @queryParam filters.* The filters.
  122. * @queryParam url_encoded Used for testing that URL parameters will be URL-encoded where needed. Example: + []&=
  123. */
  124. public function withQueryParameters()
  125. {
  126. return '';
  127. }
  128. /**
  129. * @bodyParam included string required Exists in examples. Example: 'Here'
  130. * @bodyParam excluded_body_param int Does not exist in examples. No-example
  131. * @queryParam excluded_query_param Does not exist in examples. No-example
  132. */
  133. public function withExcludedExamples()
  134. {
  135. return '';
  136. }
  137. /**
  138. * @authenticated
  139. * @responseField user_id string The ID of the newly created user
  140. * @responseField creator_id string The ID of the creator
  141. */
  142. public function withAuthenticatedTag()
  143. {
  144. return '';
  145. }
  146. /**
  147. * @responseField user_id string The ID of the newly created user
  148. * @responseField creator_id string The ID of the creator
  149. */
  150. public function withResponseFieldTag()
  151. {
  152. return '';
  153. }
  154. /**
  155. * @apiResource \Knuckles\Scribe\Tests\Fixtures\TestUserApiResource
  156. * @apiResourceModel \Knuckles\Scribe\Tests\Fixtures\TestUser
  157. */
  158. public function withEloquentApiResource()
  159. {
  160. return new TestUserApiResource(Utils::getModelFactory(TestUser::class)->make(['id' => 0]));
  161. }
  162. /**
  163. * @group Other😎
  164. *
  165. * @apiResourceCollection Knuckles\Scribe\Tests\Fixtures\TestUserApiResource
  166. * @apiResourceModel Knuckles\Scribe\Tests\Fixtures\TestUser
  167. */
  168. public function withEloquentApiResourceCollection()
  169. {
  170. return TestUserApiResource::collection(
  171. collect([Utils::getModelFactory(TestUser::class)->make(['id' => 0])])
  172. );
  173. }
  174. /**
  175. * @group Other😎
  176. *
  177. * @apiResourceCollection Knuckles\Scribe\Tests\Fixtures\TestUserApiResourceCollection
  178. * @apiResourceModel Knuckles\Scribe\Tests\Fixtures\TestUser
  179. */
  180. public function withEloquentApiResourceCollectionClass()
  181. {
  182. return new TestUserApiResourceCollection(
  183. collect([Utils::getModelFactory(TestUser::class)->make(['id' => 0])])
  184. );
  185. }
  186. public function checkCustomHeaders(Request $request)
  187. {
  188. return $request->headers->all();
  189. }
  190. public function shouldFetchRouteResponse()
  191. {
  192. $fruit = new \stdClass();
  193. $fruit->id = 4;
  194. $fruit->name = ' banana ';
  195. $fruit->color = 'RED';
  196. $fruit->weight = 1;
  197. $fruit->delicious = true;
  198. return [
  199. 'id' => (int) $fruit->id,
  200. 'name' => trim($fruit->name),
  201. 'color' => strtolower($fruit->color),
  202. 'weight' => $fruit->weight . ' kg',
  203. 'delicious' => $fruit->delicious,
  204. 'responseCall' => true,
  205. ];
  206. }
  207. public function echoesConfig()
  208. {
  209. return [
  210. 'app.env' => config('app.env'),
  211. ];
  212. }
  213. /**
  214. * @group Other😎
  215. *
  216. * @urlParam param required Example: 4
  217. * @urlParam param2
  218. * @urlParam param4 No-example.
  219. *
  220. * @queryParam something
  221. */
  222. public function echoesUrlParameters($param, $param2, $param3 = null, $param4 = null)
  223. {
  224. return compact('param', 'param2', 'param3', 'param4');
  225. }
  226. /**
  227. * @authenticated
  228. * @urlparam $id Example: 3
  229. */
  230. public function shouldFetchRouteResponseWithEchoedSettings($id)
  231. {
  232. return [
  233. '{id}' => $id,
  234. 'header' => request()->header('header'),
  235. 'auth' => request()->header('Authorization'),
  236. 'queryParam' => request()->query('queryParam'),
  237. 'bodyParam' => request()->get('bodyParam'),
  238. ];
  239. }
  240. /**
  241. * @response {
  242. * "result": "Лорем ипсум долор сит амет"
  243. * }
  244. */
  245. public function withUtf8ResponseTag()
  246. {
  247. return ['result' => 'Лорем ипсум долор сит амет'];
  248. }
  249. /**
  250. * @hideFromAPIDocumentation
  251. */
  252. public function skip()
  253. {
  254. }
  255. /**
  256. * @response {
  257. * "id": 4,
  258. * "name": "banana",
  259. * "color": "red",
  260. * "weight": "1 kg",
  261. * "delicious": true,
  262. * "responseTag": true
  263. * }
  264. */
  265. public function withResponseTag()
  266. {
  267. GeneratorTestCase::$globalValue = rand();
  268. return '';
  269. }
  270. /**
  271. * @response 422 {
  272. * "message": "Validation error"
  273. * }
  274. */
  275. public function withResponseTagAndStatusCode()
  276. {
  277. return '';
  278. }
  279. /**
  280. * @response {
  281. * "id": 4,
  282. * "name": "banana",
  283. * "color": "red",
  284. * "weight": "1 kg",
  285. * "delicious": true,
  286. * "multipleResponseTagsAndStatusCodes": true
  287. * }
  288. * @response 401 {
  289. * "message": "Unauthorized"
  290. * }
  291. */
  292. public function withMultipleResponseTagsAndStatusCode()
  293. {
  294. return '';
  295. }
  296. /**
  297. * @transformer \Knuckles\Scribe\Tests\Fixtures\TestTransformer
  298. */
  299. public function transformerTag()
  300. {
  301. return '';
  302. }
  303. /**
  304. * @transformer 201 \Knuckles\Scribe\Tests\Fixtures\TestTransformer
  305. */
  306. public function transformerTagWithStatusCode()
  307. {
  308. return '';
  309. }
  310. /**
  311. * @transformer \Knuckles\Scribe\Tests\Fixtures\TestTransformer
  312. * @transformermodel \Knuckles\Scribe\Tests\Fixtures\TestModel
  313. */
  314. public function transformerTagWithModel()
  315. {
  316. return '';
  317. }
  318. /**
  319. * @transformercollection \Knuckles\Scribe\Tests\Fixtures\TestTransformer
  320. */
  321. public function transformerCollectionTag()
  322. {
  323. return '';
  324. }
  325. /**
  326. * @transformercollection \Knuckles\Scribe\Tests\Fixtures\TestTransformer
  327. * @transformermodel \Knuckles\Scribe\Tests\Fixtures\TestModel
  328. */
  329. public function transformerCollectionTagWithModel()
  330. {
  331. return '';
  332. }
  333. /**
  334. * @responseFile response_test.json
  335. */
  336. public function responseFileTag()
  337. {
  338. return '';
  339. }
  340. /**
  341. * @responseFile response_test.json
  342. * @responseFile 401 response_error_test.json
  343. */
  344. public function withResponseFileTagAndStatusCode()
  345. {
  346. return '';
  347. }
  348. /**
  349. * @responseFile response_test.json {"message" : "Serendipity"}
  350. */
  351. public function responseFileTagAndCustomJson()
  352. {
  353. return '';
  354. }
  355. /**
  356. * @responseFile i-do-not-exist.json
  357. */
  358. public function withNonExistentResponseFile()
  359. {
  360. return '';
  361. }
  362. }