TestController.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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
  67. * @bodyParam even_more_param array
  68. * @bodyParam book.name string
  69. * @bodyParam book.author_id integer
  70. * @bodyParam book[pages_count] integer
  71. * @bodyParam ids.* integer
  72. * @bodyParam users.*.first_name string The first name of the user. Example: John
  73. * @bodyParam users.*.last_name string The last name of the user. Example: Doe
  74. */
  75. public function withBodyParameters()
  76. {
  77. return '';
  78. }
  79. public function withFormRequestParameter(TestRequest $request)
  80. {
  81. return '';
  82. }
  83. public function withMultipleFormRequestParameters(string $test, TestRequest $request)
  84. {
  85. return '';
  86. }
  87. /**
  88. * @bodyParam direct_one string Is found directly on the method.
  89. */
  90. public function withNonCommentedFormRequestParameter(TestNonCommentedRequest $request)
  91. {
  92. return '';
  93. }
  94. /**
  95. * @queryParam location_id required The id of the location.
  96. * @queryParam user_id required The id of the user. Example: me
  97. * @queryParam page required The page number. Example: 4
  98. * @queryParam filters The filters.
  99. * @queryParam url_encoded Used for testing that URL parameters will be URL-encoded where needed. Example: + []&=
  100. */
  101. public function withQueryParameters()
  102. {
  103. return '';
  104. }
  105. /**
  106. * @bodyParam included string required Exists in examples. Example: 'Here'
  107. * @bodyParam excluded_body_param int Does not exist in examples. No-example
  108. * @queryParam excluded_query_param Does not exist in examples. No-example
  109. */
  110. public function withExcludedExamples()
  111. {
  112. return '';
  113. }
  114. /**
  115. * @authenticated
  116. */
  117. public function withAuthenticatedTag()
  118. {
  119. return '';
  120. }
  121. public function checkCustomHeaders(Request $request)
  122. {
  123. return $request->headers->all();
  124. }
  125. public function shouldFetchRouteResponse()
  126. {
  127. $fruit = new \stdClass();
  128. $fruit->id = 4;
  129. $fruit->name = ' banana ';
  130. $fruit->color = 'RED';
  131. $fruit->weight = 1;
  132. $fruit->delicious = true;
  133. return [
  134. 'id' => (int) $fruit->id,
  135. 'name' => trim($fruit->name),
  136. 'color' => strtolower($fruit->color),
  137. 'weight' => $fruit->weight.' kg',
  138. 'delicious' => $fruit->delicious,
  139. 'responseCall' => true,
  140. ];
  141. }
  142. public function echoesConfig()
  143. {
  144. return [
  145. 'app.env' => config('app.env'),
  146. ];
  147. }
  148. public function echoesUrlPathParameters($param)
  149. {
  150. return [
  151. 'param' => $param,
  152. ];
  153. }
  154. public function shouldFetchRouteResponseWithEchoedSettings($id)
  155. {
  156. return [
  157. '{id}' => $id,
  158. 'APP_ENV' => getenv('APP_ENV'),
  159. 'header' => request()->header('header'),
  160. 'queryParam' => request()->query('queryParam'),
  161. 'bodyParam' => request()->get('bodyParam'),
  162. ];
  163. }
  164. /**
  165. * @response {
  166. * "result": "Лорем ипсум долор сит амет"
  167. * }
  168. */
  169. public function withUtf8ResponseTag()
  170. {
  171. return ['result' => 'Лорем ипсум долор сит амет'];
  172. }
  173. /**
  174. * @hideFromAPIDocumentation
  175. */
  176. public function skip()
  177. {
  178. }
  179. /**
  180. * @response {
  181. * "id": 4,
  182. * "name": "banana",
  183. * "color": "red",
  184. * "weight": "1 kg",
  185. * "delicious": true,
  186. * "responseTag": true
  187. * }
  188. */
  189. public function withResponseTag()
  190. {
  191. return '';
  192. }
  193. /**
  194. * @response 422 {
  195. * "message": "Validation error"
  196. * }
  197. */
  198. public function withResponseTagAndStatusCode()
  199. {
  200. return '';
  201. }
  202. /**
  203. * @response {
  204. * "id": 4,
  205. * "name": "banana",
  206. * "color": "red",
  207. * "weight": "1 kg",
  208. * "delicious": true,
  209. * "multipleResponseTagsAndStatusCodes": true
  210. * }
  211. * @response 401 {
  212. * "message": "Unauthorized"
  213. * }
  214. */
  215. public function withMultipleResponseTagsAndStatusCode()
  216. {
  217. return '';
  218. }
  219. /**
  220. * @transformer \Mpociot\ApiDoc\Tests\Fixtures\TestTransformer
  221. */
  222. public function transformerTag()
  223. {
  224. return '';
  225. }
  226. /**
  227. * @transformer \Mpociot\ApiDoc\Tests\Fixtures\TestTransformer
  228. * @transformermodel \Mpociot\ApiDoc\Tests\Fixtures\TestModel
  229. */
  230. public function transformerTagWithModel()
  231. {
  232. return '';
  233. }
  234. /**
  235. * @transformercollection \Mpociot\ApiDoc\Tests\Fixtures\TestTransformer
  236. */
  237. public function transformerCollectionTag()
  238. {
  239. return '';
  240. }
  241. /**
  242. * @transformercollection \Mpociot\ApiDoc\Tests\Fixtures\TestTransformer
  243. * @transformermodel \Mpociot\ApiDoc\Tests\Fixtures\TestModel
  244. */
  245. public function transformerCollectionTagWithModel()
  246. {
  247. return '';
  248. }
  249. /**
  250. * @responseFile response_test.json
  251. */
  252. public function responseFileTag()
  253. {
  254. return '';
  255. }
  256. /**
  257. * @responseFile response_test.json
  258. * @responseFile 401 response_error_test.json
  259. */
  260. public function withResponseFileTagAndStatusCode()
  261. {
  262. return '';
  263. }
  264. /**
  265. * @responseFile response_test.json {"message" : "Serendipity"}
  266. */
  267. public function responseFileTagAndCustomJson()
  268. {
  269. return '';
  270. }
  271. }