TestController.php 9.8 KB

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