GithubHelp home page GithubHelp logo

jeffersonsimaogoncalves / ladocumenter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from icodestuff-io/ladocumenter

1.0 1.0 0.0 143 KB

Automatically generate beautiful API documentation for your Laravel API routes using annotations.

License: MIT License

JavaScript 4.61% PHP 90.62% Blade 4.76%

ladocumenter's Introduction

logo

CircleCI Total Downloads Latest Stable Version License

Automatically generate beautiful API documentation for your Laravel API routes using annotations.

Installation

PHP 7.4 and Laravel 7 or higher are required.

Install LaRecipe

You will need LaRecipe to serve your autogenerated markdown

composer require binarytorch/larecipe

Then run

php artisan larecipe:install

Install LaDocumenter

After installing LaRecipe you can now install LaDocumenter

composer require icodestuff/ladocumenter

Then publish the config

php artisan vendor:publish --provider="Icodestuff\LaDocumenter\LaDocumenterServiceProvider"

Demo Video

Here is a YouTube video showcasing the LaDocumenter package

Demo

Getting Started

The only endpoints that are documented are the ones in your api.php file.

Generating Documentation

In order to compile your annotations to markdown you will need to run:

php artisan ladocumenter:generate

Grouping Endpoints

All endpoints are grouped for easy organization. Only use @Group to group endpoints in a single controller class by adding it to the top of the controller like so:

Example
/**
 * @Group(name="Foo", description="This is an example group.")
 */
class FooController extends Controller
{

}
Attributes
  • Name (required)
  • Description (optional)

Documenting Endpoints

The @Endpoint annotation is used for a single controller method or endpoint. Note, at this time we don't support closures or resources ๐Ÿ˜•

Example

class FooController extends Controller
{
    /**
    * @Endpoint(name="Example", description="This is an example endpoint.")
     */
    public function bar()
    {
    
    }
}
Attributes
  • Name (required)
  • Description (optional)

Specifying Request Parameters

To specify a list of valid parameters your API route accepts, use the @QueryParam or @BodyParam.

Both the @BodyParam & @QueryParam annotation takes the name, type, required, description and an example.

@BodyParam Example

class FooController extends Controller
{
    /**
    * @BodyParam(name="foo", type="string", status="required", description="An example body paramater", example="bar")
     */
    public function bar(FormRequest $request)
    {
    
    }
}

@QueryParam Example

class FooController extends Controller
{
    /**
    * @QueryParam(name="foo", type="string", status="optional", description="An example query paramater", example="bar")
     */
    public function bar()
    {
    
    }
}

Attributes

  • Name (required)
  • Type (required)
  • IsRequired (required)
  • Description (optional)
  • Example (optional)

Generating Responses

To generate a response, you must use the @ResponseExample annotation. This takes in the status of the response as well as a link to the response file like so:

class FooController extends Controller
{
    /**
    * @ResponseExample(status=200, file="responses/example.json")
     */
    public function bar()
    {
        return response()->json(['foo' => 'bar']);
    }
}
Attributes
  • Status (required)
  • Example (required)

Be sure to add your responses to the storage directory as that is where LaDocumenter looks for them. We recommend automatically generating responses using Laravel's testing suite.

Indicating Authentication Status

LaDocumenter automatically labels an endpoint as authenticated if the route uses the middleware defined in the config/ladocumenter.php file:

'auth_middleware' => [
    'auth:sanctum',
    'auth'
],

If you are using a separate auth middleware, be sure to define it in the config file.

ladocumenter's People

Contributors

solomon04 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.