TestController.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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. * @authenticated
  217. * @urlparam $id Example: 3
  218. */
  219. public function shouldFetchRouteResponseWithEchoedSettings($id)
  220. {
  221. return [
  222. '{id}' => $id,
  223. 'header' => request()->header('header'),
  224. 'auth' => request()->header('Authorization'),
  225. 'queryParam' => request()->query('queryParam'),
  226. 'bodyParam' => request()->get('bodyParam'),
  227. ];
  228. }
  229. /**
  230. * @response {
  231. * "result": "Лорем ипсум долор сит амет"
  232. * }
  233. */
  234. public function withUtf8ResponseTag()
  235. {
  236. return ['result' => 'Лорем ипсум долор сит амет'];
  237. }
  238. /**
  239. * @hideFromAPIDocumentation
  240. */
  241. public function skip()
  242. {
  243. }
  244. /**
  245. * @response {
  246. * "id": 4,
  247. * "name": "banana",
  248. * "color": "red",
  249. * "weight": "1 kg",
  250. * "delicious": true,
  251. * "responseTag": true
  252. * }
  253. */
  254. public function withResponseTag()
  255. {
  256. GeneratorTestCase::$globalValue = rand();
  257. return '';
  258. }
  259. /**
  260. * @response 422 {
  261. * "message": "Validation error"
  262. * }
  263. */
  264. public function withResponseTagAndStatusCode()
  265. {
  266. return '';
  267. }
  268. /**
  269. * @response {
  270. * "id": 4,
  271. * "name": "banana",
  272. * "color": "red",
  273. * "weight": "1 kg",
  274. * "delicious": true,
  275. * "multipleResponseTagsAndStatusCodes": true
  276. * }
  277. * @response 401 {
  278. * "message": "Unauthorized"
  279. * }
  280. */
  281. public function withMultipleResponseTagsAndStatusCode()
  282. {
  283. return '';
  284. }
  285. /**
  286. * @transformer \Knuckles\Scribe\Tests\Fixtures\TestTransformer
  287. */
  288. public function transformerTag()
  289. {
  290. return '';
  291. }
  292. /**
  293. * @transformer 201 \Knuckles\Scribe\Tests\Fixtures\TestTransformer
  294. */
  295. public function transformerTagWithStatusCode()
  296. {
  297. return '';
  298. }
  299. /**
  300. * @transformer \Knuckles\Scribe\Tests\Fixtures\TestTransformer
  301. * @transformermodel \Knuckles\Scribe\Tests\Fixtures\TestModel
  302. */
  303. public function transformerTagWithModel()
  304. {
  305. return '';
  306. }
  307. /**
  308. * @transformercollection \Knuckles\Scribe\Tests\Fixtures\TestTransformer
  309. */
  310. public function transformerCollectionTag()
  311. {
  312. return '';
  313. }
  314. /**
  315. * @transformercollection \Knuckles\Scribe\Tests\Fixtures\TestTransformer
  316. * @transformermodel \Knuckles\Scribe\Tests\Fixtures\TestModel
  317. */
  318. public function transformerCollectionTagWithModel()
  319. {
  320. return '';
  321. }
  322. /**
  323. * @responseFile response_test.json
  324. */
  325. public function responseFileTag()
  326. {
  327. return '';
  328. }
  329. /**
  330. * @responseFile response_test.json
  331. * @responseFile 401 response_error_test.json
  332. */
  333. public function withResponseFileTagAndStatusCode()
  334. {
  335. return '';
  336. }
  337. /**
  338. * @responseFile response_test.json {"message" : "Serendipity"}
  339. */
  340. public function responseFileTagAndCustomJson()
  341. {
  342. return '';
  343. }
  344. /**
  345. * @responseFile i-do-not-exist.json
  346. */
  347. public function withNonExistentResponseFile()
  348. {
  349. return '';
  350. }
  351. }