TestController.php 9.5 KB

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