TestController.php 9.8 KB

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