TestController.php 10.0 KB

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