TestController.php 9.2 KB

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