diff --git a/tests/Fixtures/partial_resource_index.md b/tests/Fixtures/partial_resource_index.md new file mode 100644 index 00000000..25400b90 --- /dev/null +++ b/tests/Fixtures/partial_resource_index.md @@ -0,0 +1,104 @@ +--- +title: API Reference + +language_tabs: +- bash +- javascript + +includes: + +search: true + +toc_footers: +- Documentation Powered by Documentarian +--- + +# Info + +Welcome to the generated API reference. +[Get Postman Collection](http://localhost/docs/collection.json) + + + +#general + +## Display a listing of the resource. + +> Example request: + +```bash +curl -X GET -G "http://localhost/api/user" \ + -H "Accept: application/json" +``` + +```javascript +var settings = { + "async": true, + "crossDomain": true, + "url": "http://localhost/api/user", + "method": "GET", + "headers": { + "accept": "application/json" + } +} + +$.ajax(settings).done(function (response) { + console.log(response); +}); +``` + +> Example response: + +```json +{ + "index_resource": true +} +``` + +### HTTP Request +`GET api/user` + + + + + +## Show the form for creating a new resource. + +> Example request: + +```bash +curl -X GET -G "http://localhost/api/user/create" \ + -H "Accept: application/json" +``` + +```javascript +var settings = { + "async": true, + "crossDomain": true, + "url": "http://localhost/api/user/create", + "method": "GET", + "headers": { + "accept": "application/json" + } +} + +$.ajax(settings).done(function (response) { + console.log(response); +}); +``` + +> Example response: + +```json +{ + "create_resource": true +} +``` + +### HTTP Request +`GET api/user/create` + + + + + diff --git a/tests/GenerateDocumentationTest.php b/tests/GenerateDocumentationTest.php index 836200c8..757a2593 100644 --- a/tests/GenerateDocumentationTest.php +++ b/tests/GenerateDocumentationTest.php @@ -127,6 +127,33 @@ public function testCanParseResourceRoutes() $this->assertFilesHaveSameContent($fixtureMarkdown, $generatedMarkdown); } + public function testCanParsePartialResourceRoutes() + { + RouteFacade::resource('/api/user', TestResourceController::class, [ + 'only' => [ + 'index', 'create' + ] + ]); + $output = $this->artisan('api:generate', [ + '--routePrefix' => 'api/*', + ]); + $fixtureMarkdown = __DIR__.'/Fixtures/partial_resource_index.md'; + $generatedMarkdown = __DIR__.'/../public/docs/source/index.md'; + $this->assertFilesHaveSameContent($fixtureMarkdown, $generatedMarkdown); + + RouteFacade::apiResource('/api/user', TestResourceController::class, [ + 'only' => [ + 'index', 'create' + ] + ]); + $output = $this->artisan('api:generate', [ + '--routePrefix' => 'api/*', + ]); + $fixtureMarkdown = __DIR__.'/Fixtures/partial_resource_index.md'; + $generatedMarkdown = __DIR__.'/../public/docs/source/index.md'; + $this->assertFilesHaveSameContent($fixtureMarkdown, $generatedMarkdown); + } + public function testGeneratedMarkdownFileIsCorrect() { RouteFacade::get('/api/test', TestController::class.'@parseMethodDescription');