TestController.php 8.4 KB

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