TestController.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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(
  140. collect([factory(TestUser::class)->make(['id' => 0])])
  141. );
  142. }
  143. /**
  144. * @group Other😎
  145. *
  146. * @apiResourceCollection Mpociot\ApiDoc\Tests\Fixtures\TestUserApiResourceCollection
  147. * @apiResourceModel Mpociot\ApiDoc\Tests\Fixtures\TestUser
  148. */
  149. public function withEloquentApiResourceCollectionClass()
  150. {
  151. return new TestUserApiResourceCollection(
  152. collect([factory(TestUser::class)->make(['id' => 0])])
  153. );
  154. }
  155. public function checkCustomHeaders(Request $request)
  156. {
  157. return $request->headers->all();
  158. }
  159. public function shouldFetchRouteResponse()
  160. {
  161. $fruit = new \stdClass();
  162. $fruit->id = 4;
  163. $fruit->name = ' banana ';
  164. $fruit->color = 'RED';
  165. $fruit->weight = 1;
  166. $fruit->delicious = true;
  167. return [
  168. 'id' => (int) $fruit->id,
  169. 'name' => trim($fruit->name),
  170. 'color' => strtolower($fruit->color),
  171. 'weight' => $fruit->weight.' kg',
  172. 'delicious' => $fruit->delicious,
  173. 'responseCall' => true,
  174. ];
  175. }
  176. public function echoesConfig()
  177. {
  178. return [
  179. 'app.env' => config('app.env'),
  180. ];
  181. }
  182. /**
  183. * @group Other😎
  184. *
  185. * @urlParam param required Example: 4
  186. * @urlParam param2
  187. * @urlParam param4 No-example.
  188. *
  189. * @queryParam something
  190. */
  191. public function echoesUrlParameters($param, $param2, $param3 = null, $param4 = null)
  192. {
  193. return compact('param', 'param2', 'param3', 'param4');
  194. }
  195. /**
  196. * @urlparam $id Example: 3
  197. */
  198. public function shouldFetchRouteResponseWithEchoedSettings($id)
  199. {
  200. return [
  201. '{id}' => $id,
  202. 'header' => request()->header('header'),
  203. 'queryParam' => request()->query('queryParam'),
  204. 'bodyParam' => request()->get('bodyParam'),
  205. ];
  206. }
  207. /**
  208. * @response {
  209. * "result": "Лорем ипсум долор сит амет"
  210. * }
  211. */
  212. public function withUtf8ResponseTag()
  213. {
  214. return ['result' => 'Лорем ипсум долор сит амет'];
  215. }
  216. /**
  217. * @hideFromAPIDocumentation
  218. */
  219. public function skip()
  220. {
  221. }
  222. /**
  223. * @response {
  224. * "id": 4,
  225. * "name": "banana",
  226. * "color": "red",
  227. * "weight": "1 kg",
  228. * "delicious": true,
  229. * "responseTag": true
  230. * }
  231. */
  232. public function withResponseTag()
  233. {
  234. return '';
  235. }
  236. /**
  237. * @response 422 {
  238. * "message": "Validation error"
  239. * }
  240. */
  241. public function withResponseTagAndStatusCode()
  242. {
  243. return '';
  244. }
  245. /**
  246. * @response {
  247. * "id": 4,
  248. * "name": "banana",
  249. * "color": "red",
  250. * "weight": "1 kg",
  251. * "delicious": true,
  252. * "multipleResponseTagsAndStatusCodes": true
  253. * }
  254. * @response 401 {
  255. * "message": "Unauthorized"
  256. * }
  257. */
  258. public function withMultipleResponseTagsAndStatusCode()
  259. {
  260. return '';
  261. }
  262. /**
  263. * @transformer \Mpociot\ApiDoc\Tests\Fixtures\TestTransformer
  264. */
  265. public function transformerTag()
  266. {
  267. return '';
  268. }
  269. /**
  270. * @transformer 201 \Mpociot\ApiDoc\Tests\Fixtures\TestTransformer
  271. */
  272. public function transformerTagWithStatusCode()
  273. {
  274. return '';
  275. }
  276. /**
  277. * @transformer \Mpociot\ApiDoc\Tests\Fixtures\TestTransformer
  278. * @transformermodel \Mpociot\ApiDoc\Tests\Fixtures\TestModel
  279. */
  280. public function transformerTagWithModel()
  281. {
  282. return '';
  283. }
  284. /**
  285. * @transformercollection \Mpociot\ApiDoc\Tests\Fixtures\TestTransformer
  286. */
  287. public function transformerCollectionTag()
  288. {
  289. return '';
  290. }
  291. /**
  292. * @transformercollection \Mpociot\ApiDoc\Tests\Fixtures\TestTransformer
  293. * @transformermodel \Mpociot\ApiDoc\Tests\Fixtures\TestModel
  294. */
  295. public function transformerCollectionTagWithModel()
  296. {
  297. return '';
  298. }
  299. /**
  300. * @responseFile response_test.json
  301. */
  302. public function responseFileTag()
  303. {
  304. return '';
  305. }
  306. /**
  307. * @responseFile response_test.json
  308. * @responseFile 401 response_error_test.json
  309. */
  310. public function withResponseFileTagAndStatusCode()
  311. {
  312. return '';
  313. }
  314. /**
  315. * @responseFile response_test.json {"message" : "Serendipity"}
  316. */
  317. public function responseFileTagAndCustomJson()
  318. {
  319. return '';
  320. }
  321. }