GenerateDocumentationTest.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <?php
  2. namespace Knuckles\Scribe\Tests;
  3. use Illuminate\Support\Facades\Route as RouteFacade;
  4. use Knuckles\Scribe\Tests\Fixtures\TestController;
  5. use Knuckles\Scribe\Tests\Fixtures\TestGroupController;
  6. use Knuckles\Scribe\Tests\Fixtures\TestIgnoreThisController;
  7. use Knuckles\Scribe\Tests\Fixtures\TestPartialResourceController;
  8. use Knuckles\Scribe\Tests\Fixtures\TestResourceController;
  9. use Knuckles\Scribe\Tests\Fixtures\TestUser;
  10. use Knuckles\Scribe\Tools\Utils;
  11. use Symfony\Component\DomCrawler\Crawler;
  12. use Symfony\Component\Yaml\Yaml;
  13. class GenerateDocumentationTest extends BaseLaravelTest
  14. {
  15. use TestHelpers;
  16. protected function setUp(): void
  17. {
  18. parent::setUp();
  19. config(['scribe.database_connections_to_transact' => []]);
  20. // Skip these ones for faster tests
  21. config(['scribe.openapi.enabled' => false]);
  22. config(['scribe.postman.enabled' => false]);
  23. $factory = app(\Illuminate\Database\Eloquent\Factory::class);
  24. $factory->define(TestUser::class, function () {
  25. return [
  26. 'id' => 4,
  27. 'first_name' => 'Tested',
  28. 'last_name' => 'Again',
  29. 'email' => 'a@b.com',
  30. ];
  31. });
  32. }
  33. public function tearDown(): void
  34. {
  35. Utils::deleteDirectoryAndContents('public/docs');
  36. Utils::deleteDirectoryAndContents('.scribe');
  37. }
  38. /** @test */
  39. public function can_process_traditional_laravel_route_syntax()
  40. {
  41. RouteFacade::get('/api/test', [TestController::class, 'withEndpointDescription']);
  42. config(['scribe.routes.0.match.prefixes' => ['api/*']]);
  43. $output = $this->artisan('scribe:generate');
  44. $this->assertStringContainsString('Processed route: [GET] api/test', $output);
  45. }
  46. /** @test */
  47. public function can_process_traditional_laravel_head_routes()
  48. {
  49. RouteFacade::addRoute('HEAD', '/api/test', [TestController::class, 'withEndpointDescription']);
  50. config(['scribe.routes.0.match.prefixes' => ['api/*']]);
  51. $output = $this->artisan('scribe:generate');
  52. $this->assertStringContainsString('Processed route: [HEAD] api/test', $output);
  53. }
  54. /**
  55. * @test
  56. * @see https://github.com/knuckleswtf/scribe/issues/53
  57. */
  58. public function can_process_closure_routes()
  59. {
  60. RouteFacade::get('/api/closure', function () {
  61. return 'hi';
  62. });
  63. config(['scribe.routes.0.match.prefixes' => ['api/*']]);
  64. $output = $this->artisan('scribe:generate');
  65. $this->assertStringContainsString('Processed route: [GET] api/closure', $output);
  66. }
  67. /**
  68. * @group dingo
  69. * @test
  70. */
  71. public function can_process_routes_on_dingo()
  72. {
  73. $api = app(\Dingo\Api\Routing\Router::class);
  74. $api->version('v1', function ($api) {
  75. $api->get('/closure', function () {
  76. return 'foo';
  77. });
  78. $api->get('/test', [TestController::class, 'withEndpointDescription']);
  79. });
  80. config(['scribe.routes.0.match.prefixes' => ['*']]);
  81. config(['scribe.routes.0.match.versions' => ['v1']]);
  82. $output = $this->artisan('scribe:generate');
  83. $this->assertStringContainsString('Processed route: [GET] closure', $output);
  84. $this->assertStringContainsString('Processed route: [GET] test', $output);
  85. }
  86. /** @test */
  87. public function can_process_callable_tuple_syntax()
  88. {
  89. RouteFacade::get('/api/array/test', [TestController::class, 'withEndpointDescription']);
  90. config(['scribe.routes.0.match.prefixes' => ['api/*']]);
  91. $output = $this->artisan('scribe:generate');
  92. $this->assertStringContainsString('Processed route: [GET] api/array/test', $output);
  93. }
  94. /** @test */
  95. public function can_skip_methods_and_classes_with_hidefromapidocumentation_tag()
  96. {
  97. RouteFacade::get('/api/skip', [TestController::class, 'skip']);
  98. RouteFacade::get('/api/skipClass', TestIgnoreThisController::class . '@dummy');
  99. RouteFacade::get('/api/test', [TestController::class, 'withEndpointDescription']);
  100. config(['scribe.routes.0.match.prefixes' => ['api/*']]);
  101. $output = $this->artisan('scribe:generate');
  102. $this->assertStringContainsString('Skipping route: [GET] api/skip', $output);
  103. $this->assertStringContainsString('Skipping route: [GET] api/skipClass', $output);
  104. $this->assertStringContainsString('Processed route: [GET] api/test', $output);
  105. }
  106. /** @test */
  107. public function warns_of_nonexistent_response_files()
  108. {
  109. RouteFacade::get('/api/non-existent', [TestController::class, 'withNonExistentResponseFile']);
  110. config(['scribe.routes.0.match.prefixes' => ['api/*']]);
  111. $output = $this->artisan('scribe:generate');
  112. $this->assertStringContainsString('@responseFile i-do-not-exist.json does not exist', $output);
  113. }
  114. /** @test */
  115. public function can_parse_resource_routes()
  116. {
  117. RouteFacade::resource('/api/users', TestResourceController::class)
  118. ->only(['index', 'store']);
  119. config(['scribe.routes.0.match.prefixes' => ['api/*']]);
  120. config([
  121. 'scribe.routes.0.apply.headers' => [
  122. 'Accept' => 'application/json',
  123. ],
  124. ]);
  125. $output = $this->artisan('scribe:generate');
  126. $this->assertStringContainsString('Processed route: [GET] api/users', $output);
  127. $this->assertStringContainsString('Processed route: [POST] api/users', $output);
  128. $this->assertStringNotContainsString('Processed route: [PUT,PATCH] api/users/{user}', $output);
  129. $this->assertStringNotContainsString('Processed route: [DELETE] api/users/{user}', $output);
  130. RouteFacade::apiResource('/api/users', TestResourceController::class)
  131. ->only(['index', 'store']);
  132. $output = $this->artisan('scribe:generate');
  133. $this->assertStringContainsString('Processed route: [GET] api/users', $output);
  134. $this->assertStringContainsString('Processed route: [POST] api/users', $output);
  135. $this->assertStringNotContainsString('Processed route: [PUT,PATCH] api/users/{user}', $output);
  136. $this->assertStringNotContainsString('Processed route: [DELETE] api/users/{user}', $output);
  137. }
  138. /** @test */
  139. public function supports_partial_resource_controller()
  140. {
  141. RouteFacade::resource('/api/users', TestPartialResourceController::class);
  142. config(['scribe.routes.0.match.prefixes' => ['api/*']]);
  143. $output = $this->artisan('scribe:generate');
  144. $this->assertStringContainsString('Processed route: [GET] api/users', $output);
  145. $this->assertStringContainsString('Processed route: [PUT,PATCH] api/users/{user}', $output);
  146. }
  147. /** @test */
  148. public function generated_postman_collection_file_is_correct()
  149. {
  150. RouteFacade::post('/api/withBodyParametersAsArray', [TestController::class, 'withBodyParametersAsArray']);
  151. RouteFacade::post('/api/withFormDataParams', [TestController::class, 'withFormDataParams']);
  152. RouteFacade::post('/api/withBodyParameters', [TestController::class, 'withBodyParameters']);
  153. RouteFacade::get('/api/withQueryParameters', [TestController::class, 'withQueryParameters']);
  154. RouteFacade::get('/api/withAuthTag', [TestController::class, 'withAuthenticatedTag']);
  155. RouteFacade::get('/api/echoesUrlParameters/{param}/{param2}/{param3?}/{param4?}', [TestController::class, 'echoesUrlParameters']);
  156. // We want to have the same values for params each time
  157. config(['scribe.faker_seed' => 1234]);
  158. config(['scribe.title' => 'GREAT API!']);
  159. config(['scribe.auth.enabled' => true]);
  160. config(['scribe.routes.0.match.prefixes' => ['api/*']]);
  161. config(['scribe.postman.overrides' => [
  162. 'info.version' => '3.9.9',
  163. ]]);
  164. config([
  165. 'scribe.routes.0.apply.headers' => [
  166. 'Custom-Header' => 'NotSoCustom',
  167. ],
  168. ]);
  169. config(['scribe.postman.enabled' => true]);
  170. $this->artisan('scribe:generate');
  171. $generatedCollection = json_decode(file_get_contents(__DIR__ . '/../public/docs/collection.json'), true);
  172. // The Postman ID varies from call to call; erase it to make the test data reproducible.
  173. $generatedCollection['info']['_postman_id'] = '';
  174. $fixtureCollection = json_decode(file_get_contents(__DIR__ . '/Fixtures/collection.json'), true);
  175. $this->assertEquals($fixtureCollection, $generatedCollection);
  176. }
  177. /** @test */
  178. public function generated_openapi_spec_file_is_correct()
  179. {
  180. RouteFacade::post('/api/withBodyParametersAsArray', [TestController::class, 'withBodyParametersAsArray']);
  181. RouteFacade::post('/api/withFormDataParams', [TestController::class, 'withFormDataParams']);
  182. RouteFacade::get('/api/withResponseTag', [TestController::class, 'withResponseTag']);
  183. RouteFacade::get('/api/withQueryParameters', [TestController::class, 'withQueryParameters']);
  184. RouteFacade::get('/api/withAuthTag', [TestController::class, 'withAuthenticatedTag']);
  185. RouteFacade::get('/api/echoesUrlParameters/{param}/{param2}/{param3?}/{param4?}', [TestController::class, 'echoesUrlParameters']);
  186. // We want to have the same values for params each time
  187. config(['scribe.faker_seed' => 1234]);
  188. config(['scribe.openapi.enabled' => true]);
  189. config(['scribe.openapi.overrides' => [
  190. 'info.version' => '3.9.9',
  191. ]]);
  192. config(['scribe.routes.0.match.prefixes' => ['api/*']]);
  193. config([
  194. 'scribe.routes.0.apply.headers' => [
  195. 'Custom-Header' => 'NotSoCustom',
  196. ],
  197. ]);
  198. $this->artisan('scribe:generate');
  199. $generatedSpec = Yaml::parseFile(__DIR__ . '/../public/docs/openapi.yaml');
  200. $fixtureSpec = Yaml::parseFile(__DIR__ . '/Fixtures/openapi.yaml');
  201. $this->assertEquals($fixtureSpec, $generatedSpec);
  202. }
  203. /** @test */
  204. public function can_append_custom_http_headers()
  205. {
  206. RouteFacade::get('/api/headers', [TestController::class, 'checkCustomHeaders']);
  207. config(['scribe.routes.0.match.prefixes' => ['api/*']]);
  208. config([
  209. 'scribe.routes.0.apply.headers' => [
  210. 'Authorization' => 'customAuthToken',
  211. 'Custom-Header' => 'NotSoCustom',
  212. ],
  213. ]);
  214. $this->artisan('scribe:generate');
  215. $endpointDetails = Yaml::parseFile(__DIR__ . '/../.scribe/endpoints/00.yaml')['endpoints'][0];
  216. $this->assertEquals("customAuthToken", $endpointDetails['headers']["Authorization"]);
  217. $this->assertEquals("NotSoCustom", $endpointDetails['headers']["Custom-Header"]);
  218. }
  219. /** @test */
  220. public function can_parse_utf8_response()
  221. {
  222. RouteFacade::get('/api/utf8', [TestController::class, 'withUtf8ResponseTag']);
  223. config(['scribe.routes.0.match.prefixes' => ['api/*']]);
  224. $this->artisan('scribe:generate');
  225. $generatedHtml = file_get_contents('public/docs/index.html');
  226. $this->assertStringContainsString('Лорем ипсум долор сит амет', $generatedHtml);
  227. }
  228. /** @test */
  229. public function sorts_group_naturally()
  230. {
  231. RouteFacade::get('/api/action1', TestGroupController::class . '@action1');
  232. RouteFacade::get('/api/action1b', TestGroupController::class . '@action1b');
  233. RouteFacade::get('/api/action2', TestGroupController::class . '@action2');
  234. RouteFacade::get('/api/action10', TestGroupController::class . '@action10');
  235. config(['scribe.routes.0.match.prefixes' => ['api/*']]);
  236. $this->artisan('scribe:generate');
  237. $this->assertFileExists(__DIR__ . '/../.scribe/endpoints/00.yaml');
  238. $this->assertFileExists(__DIR__ . '/../.scribe/endpoints/01.yaml');
  239. $this->assertFileExists(__DIR__ . '/../.scribe/endpoints/02.yaml');
  240. $this->assertEquals('1. Group 1', Yaml::parseFile(__DIR__ . '/../.scribe/endpoints/00.yaml')['name']);
  241. $this->assertEquals('2. Group 2', Yaml::parseFile(__DIR__ . '/../.scribe/endpoints/01.yaml')['name']);
  242. $this->assertEquals('10. Group 10', Yaml::parseFile(__DIR__ . '/../.scribe/endpoints/02.yaml')['name']);
  243. }
  244. /** @test */
  245. public function can_customise_static_output_path()
  246. {
  247. RouteFacade::get('/api/action1', TestGroupController::class . '@action1');
  248. config(['scribe.routes.0.match.prefixes' => ['*']]);
  249. config(['scribe.static.output_path' => 'static/docs']);
  250. $this->artisan('scribe:generate');
  251. $this->assertFileExists('static/docs/index.html');
  252. Utils::deleteDirectoryAndContents('static/');
  253. }
  254. /** @test */
  255. public function will_not_overwrite_manually_modified_content_unless_force_flag_is_set()
  256. {
  257. RouteFacade::get('/api/action1', [TestGroupController::class, 'action1']);
  258. RouteFacade::get('/api/action1b', [TestGroupController::class, 'action1b']);
  259. config(['scribe.routes.0.match.prefixes' => ['api/*']]);
  260. config(['scribe.routes.0.apply.response_calls.methods' => []]);
  261. $this->artisan('scribe:generate');
  262. $authFilePath = '.scribe/auth.md';
  263. $group1FilePath = '.scribe/endpoints/00.yaml';
  264. $group = Yaml::parseFile($group1FilePath);
  265. $this->assertEquals('api/action1', $group['endpoints'][0]['uri']);
  266. $this->assertEquals([], $group['endpoints'][0]['urlParameters']);
  267. $extraParam = [
  268. 'name' => 'a_param',
  269. 'description' => 'A URL param.',
  270. 'required' => true,
  271. 'example' => 6,
  272. 'type' => 'integer',
  273. 'custom' => [],
  274. ];
  275. $group['endpoints'][0]['urlParameters']['a_param'] = $extraParam;
  276. file_put_contents($group1FilePath, Yaml::dump(
  277. $group, 20, 2,
  278. Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP
  279. ));
  280. file_put_contents($authFilePath, 'Some other useful stuff.', FILE_APPEND);
  281. $this->artisan('scribe:generate');
  282. $group = Yaml::parseFile($group1FilePath);
  283. $this->assertEquals('api/action1', $group['endpoints'][0]['uri']);
  284. $this->assertEquals(['a_param' => $extraParam], $group['endpoints'][0]['urlParameters']);
  285. $this->assertStringContainsString('Some other useful stuff.', file_get_contents($authFilePath));
  286. $this->artisan('scribe:generate', ['--force' => true]);
  287. $group = Yaml::parseFile($group1FilePath);
  288. $this->assertEquals('api/action1', $group['endpoints'][0]['uri']);
  289. $this->assertEquals([], $group['endpoints'][0]['urlParameters']);
  290. $this->assertStringNotContainsString('Some other useful stuff.', file_get_contents($authFilePath));
  291. }
  292. /** @test */
  293. public function generates_correct_url_params_from_resource_routes_and_field_bindings()
  294. {
  295. if (version_compare($this->app->version(), '7.0.0', '<')) {
  296. $this->markTestSkipped("Laravel < 7.x doesn't support field binding syntax.");
  297. return;
  298. }
  299. RouteFacade::prefix('providers/{provider:slug}')->group(function () {
  300. RouteFacade::resource('users.addresses', TestPartialResourceController::class)->parameters([
  301. 'addresses' => 'address:uuid',
  302. ]);
  303. });
  304. config(['scribe.routes.0.match.prefixes' => ['*']]);
  305. config(['scribe.routes.0.apply.response_calls.methods' => []]);
  306. $this->artisan('scribe:generate');
  307. $groupA = Yaml::parseFile('.scribe/endpoints/00.yaml');
  308. $this->assertEquals('providers/{provider_slug}/users/{user_id}/addresses', $groupA['endpoints'][0]['uri']);
  309. $groupB = Yaml::parseFile('.scribe/endpoints/01.yaml');
  310. $this->assertEquals('providers/{provider_slug}/users/{user_id}/addresses/{uuid}', $groupB['endpoints'][0]['uri']);
  311. }
  312. /** @test */
  313. public function will_generate_without_extracting_if_noExtraction_flag_is_set()
  314. {
  315. config(['scribe.routes.0.exclude' => ['*']]);
  316. Utils::copyDirectory(__DIR__.'/Fixtures/.scribe', '.scribe');
  317. $output = $this->artisan('scribe:generate', ['--no-extraction' => true]);
  318. $this->assertStringNotContainsString("Processing route", $output);
  319. $crawler = new Crawler(file_get_contents('public/docs/index.html'));
  320. [$intro, $auth] = $crawler->filter('h1 + p')->getIterator();
  321. $this->assertEquals('Heyaa introduction!👋', trim($intro->firstChild->textContent));
  322. $this->assertEquals('This is just a test.', trim($auth->firstChild->textContent));
  323. $group = $crawler->filter('h1')->getNode(2);
  324. $this->assertEquals('General', trim($group->textContent));
  325. $expectedEndpoint = $crawler->filter('h2');
  326. $this->assertCount(1, $expectedEndpoint);
  327. $this->assertEquals("Healthcheck", $expectedEndpoint->text());
  328. }
  329. /** @test */
  330. public function merges_and_correctly_sorts_user_defined_endpoints()
  331. {
  332. RouteFacade::get('/api/action1', [TestGroupController::class, 'action1']);
  333. RouteFacade::get('/api/action2', [TestGroupController::class, 'action2']);
  334. config(['scribe.routes.0.match.prefixes' => ['api/*']]);
  335. config(['scribe.routes.0.apply.response_calls.methods' => []]);
  336. if (!is_dir('.scribe/endpoints'))
  337. mkdir('.scribe/endpoints', 0777, true);
  338. copy(__DIR__ . '/Fixtures/custom.0.yaml', '.scribe/endpoints/custom.0.yaml');
  339. $this->artisan('scribe:generate');
  340. $crawler = new Crawler(file_get_contents('public/docs/index.html'));
  341. $headings = $crawler->filter('h1')->getIterator();
  342. // There should only be six headings — intro, auth and four groups
  343. $this->assertCount(6, $headings);
  344. [$_, $_, $group1, $group2, $group3, $group4] = $headings;
  345. $this->assertEquals('1. Group 1', trim($group1->textContent));
  346. $this->assertEquals('5. Group 5', trim($group2->textContent));
  347. $this->assertEquals('4. Group 4', trim($group3->textContent));
  348. $this->assertEquals('2. Group 2', trim($group4->textContent));
  349. $expectedEndpoints = $crawler->filter('h2');
  350. $this->assertEquals(6, $expectedEndpoints->count());
  351. // Enforce the order of the endpoints
  352. // Ideally, we should also check the groups they're under
  353. $this->assertEquals("Some endpoint.", $expectedEndpoints->getNode(0)->textContent);
  354. $this->assertEquals("User defined", $expectedEndpoints->getNode(1)->textContent);
  355. $this->assertEquals("GET withBeforeGroup", $expectedEndpoints->getNode(2)->textContent);
  356. $this->assertEquals("GET belongingToAnEarlierBeforeGroup", $expectedEndpoints->getNode(3)->textContent);
  357. $this->assertEquals("GET withAfterGroup", $expectedEndpoints->getNode(4)->textContent);
  358. $this->assertEquals("GET api/action2", $expectedEndpoints->getNode(5)->textContent);
  359. }
  360. /** @test */
  361. public function respects_endpoints_and_group_sort_order()
  362. {
  363. RouteFacade::get('/api/action1', [TestGroupController::class, 'action1']);
  364. RouteFacade::get('/api/action1b', [TestGroupController::class, 'action1b']);
  365. RouteFacade::get('/api/action2', [TestGroupController::class, 'action2']);
  366. config(['scribe.routes.0.match.prefixes' => ['api/*']]);
  367. config(['scribe.routes.0.apply.response_calls.methods' => []]);
  368. $this->artisan('scribe:generate');
  369. // First: verify the current order of the groups and endpoints
  370. $crawler = new Crawler(file_get_contents('public/docs/index.html'));
  371. $h1s = $crawler->filter('h1');
  372. $this->assertEquals('1. Group 1', trim($h1s->getNode(2)->textContent));
  373. $this->assertEquals('2. Group 2', trim($h1s->getNode(3)->textContent));
  374. $expectedEndpoints = $crawler->filter('h2');
  375. $this->assertEquals("Some endpoint.", $expectedEndpoints->getNode(0)->textContent);
  376. $this->assertEquals("Another endpoint.", $expectedEndpoints->getNode(1)->textContent);
  377. $this->assertEquals("GET api/action2", $expectedEndpoints->getNode(2)->textContent);
  378. // Now swap the endpoints
  379. $group = Yaml::parseFile('.scribe/endpoints/00.yaml');
  380. $this->assertEquals('api/action1', $group['endpoints'][0]['uri']);
  381. $this->assertEquals('api/action1b', $group['endpoints'][1]['uri']);
  382. $action1 = $group['endpoints'][0];
  383. $group['endpoints'][0] = $group['endpoints'][1];
  384. $group['endpoints'][1] = $action1;
  385. file_put_contents('.scribe/endpoints/00.yaml', Yaml::dump(
  386. $group, 20, 2,
  387. Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP
  388. ));
  389. // And then the groups
  390. rename('.scribe/endpoints/00.yaml', '.scribe/endpoints/temp.yaml');
  391. rename('.scribe/endpoints/01.yaml', '.scribe/endpoints/00.yaml');
  392. rename('.scribe/endpoints/temp.yaml', '.scribe/endpoints/1.yaml');
  393. $this->artisan('scribe:generate');
  394. $crawler = new Crawler(file_get_contents('public/docs/index.html'));
  395. $h1s = $crawler->filter('h1');
  396. $this->assertEquals('2. Group 2', trim($h1s->getNode(2)->textContent));
  397. $this->assertEquals('1. Group 1', trim($h1s->getNode(3)->textContent));
  398. $expectedEndpoints = $crawler->filter('h2');
  399. $this->assertEquals("GET api/action2", $expectedEndpoints->getNode(0)->textContent);
  400. $this->assertEquals("Another endpoint.", $expectedEndpoints->getNode(1)->textContent);
  401. $this->assertEquals("Some endpoint.", $expectedEndpoints->getNode(2)->textContent);
  402. }
  403. /** @test */
  404. public function will_auto_set_content_type_to_multipart_if_file_params_are_present()
  405. {
  406. /**
  407. * @bodyParam param string required
  408. */
  409. RouteFacade::post('no-file', fn() => null);
  410. /**
  411. * @bodyParam a_file file required
  412. */
  413. RouteFacade::post('top-level-file', fn() => null);
  414. /**
  415. * @bodyParam data object
  416. * @bodyParam data.thing string
  417. * @bodyParam data.a_file file
  418. */
  419. RouteFacade::post('nested-file', fn() => null);
  420. config(['scribe.routes.0.match.prefixes' => ['*']]);
  421. config(['scribe.routes.0.apply.response_calls.methods' => []]);
  422. $this->artisan('scribe:generate');
  423. $group = Yaml::parseFile('.scribe/endpoints/00.yaml');
  424. $this->assertEquals('no-file', $group['endpoints'][0]['uri']);
  425. $this->assertEquals('application/json', $group['endpoints'][0]['headers']['Content-Type']);
  426. $this->assertEquals('top-level-file', $group['endpoints'][1]['uri']);
  427. $this->assertEquals('multipart/form-data', $group['endpoints'][1]['headers']['Content-Type']);
  428. $this->assertEquals('nested-file', $group['endpoints'][2]['uri']);
  429. $this->assertEquals('multipart/form-data', $group['endpoints'][2]['headers']['Content-Type']);
  430. }
  431. }