TestController.php 9.9 KB

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