TestController.php 8.7 KB

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