All Projects → alt3 → cakephp-swagger

alt3 / cakephp-swagger

Licence: MIT license
Swagger plugin for documenting your CakePHP APIs

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects
PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to cakephp-swagger

cakephp-swagger-bake
Automatically generate OpenAPI, Swagger, and Redoc documentation from your existing CakePHP code.
Stars: ✭ 48 (-21.31%)
Mutual labels:  cakephp, swagger-ui
Orderly
Default ordering for your CakePHP tables
Stars: ✭ 21 (-65.57%)
Mutual labels:  cakephp
grlc
grlc builds Web APIs using shared SPARQL queries
Stars: ✭ 118 (+93.44%)
Mutual labels:  swagger-ui
spring-boot-starter-swagger
Spring Boot Swagger UI Starter
Stars: ✭ 14 (-77.05%)
Mutual labels:  swagger-ui
jekyll-swagger-ui
A Jekyll plugin to integrate Swagger UI into Jekyll site
Stars: ✭ 16 (-73.77%)
Mutual labels:  swagger-ui
project-template-cakephp
🍰 Template for CakePHP-based projects
Stars: ✭ 22 (-63.93%)
Mutual labels:  cakephp
cakephp-ajax
AJAX for CakePHP: A plugin to ease handling AJAX requests.
Stars: ✭ 55 (-9.84%)
Mutual labels:  cakephp
cakephp-glide
CakePHP plugin for using Glide image manipulation library
Stars: ✭ 34 (-44.26%)
Mutual labels:  cakephp
php-orm-benchmark
The benchmark to compare performance of PHP ORM solutions.
Stars: ✭ 82 (+34.43%)
Mutual labels:  cakephp
kanban-board
Single-click full-stack application (Postgres, Spring Boot & Angular) using Docker Compose
Stars: ✭ 138 (+126.23%)
Mutual labels:  swagger-ui
rawphp
A powerful, robust and API-first, PHP framework that helps people from different PHP backgrounds work on the same project seamlessly. You can write Laravel, CakePHP, Slim, Symphone and Procedural PHP code inside it and it all works perfectly. Its the PHP Framework for everyone.
Stars: ✭ 31 (-49.18%)
Mutual labels:  cakephp
cakephp-i18n
A CakePHP plugin with I18n related tools.
Stars: ✭ 40 (-34.43%)
Mutual labels:  cakephp
webadmin
SophiMail Webadmin and Dashboard
Stars: ✭ 48 (-21.31%)
Mutual labels:  cakephp
example-postgresql
A complete example of a "CRUD" service (UserService) built with Oat++ and using oatpp ORM with PostgreSQL.
Stars: ✭ 24 (-60.66%)
Mutual labels:  swagger-ui
cakephp-translate
A CakePHP plugin to manage translations of your static content the easy way via web backend.
Stars: ✭ 18 (-70.49%)
Mutual labels:  cakephp
openapi-viewer
Browse and test a REST API described with the OpenAPI 3.0 Specification
Stars: ✭ 85 (+39.34%)
Mutual labels:  swagger-ui
IGeekFan.AspNetCore.Knife4jUI
support .NET Core3.0+,.NET Standard2.0 Swagger UI knife4j ui,you can use NSwagger or Swashbuckle.AspNetCore in packages
Stars: ✭ 178 (+191.8%)
Mutual labels:  swagger-ui
PHP-Frameworks-Bench
Popular PHP Frameworks Benchmark.
Stars: ✭ 28 (-54.1%)
Mutual labels:  cakephp
asset-mix
Provides helpers functions for CakePHP to use Laravel Mix.
Stars: ✭ 27 (-55.74%)
Mutual labels:  cakephp
elastic-search
Elastic search datasource for CakePHP
Stars: ✭ 85 (+39.34%)
Mutual labels:  cakephp

cakephp-swagger

Build Status StyleCI Status Coverage Status Total Downloads License

CakePHP 4.x plugin that adds auto-generated Swagger 2.0 documentation to your projects using swagger-php and swagger-ui.

Requirements

Installation

Install the plugin using composer:

composer require alt3/cakephp-swagger

Enabling

Enable the plugin in the bootstrap() method found in src/Application.php:

    public function bootstrap()
    {
        parent::bootstrap();
        $this->addPlugin('Alt3/Swagger');
    }

Also make sure that AssetMiddleware is loaded inside Application.php or all Swagger page assets will 404.

Installation check

After enabling the plugin, browsing to http://your.app/alt3/swagger should now produce the Swagger-UI interface:

Default UI index

Configuration

All configuration for this plugin is done through the /config/swagger.php configuration file. TLDR full example below.

<?php
use Cake\Core\Configure;

return [
    'Swagger' => [
        'ui' => [
            'title' => 'ALT3 Swagger',
            'validator' => true,
            'api_selector' => true,
            'route' => '/swagger/',
            'schemes' => ['http', 'https']
        ],
        'docs' => [
            'crawl' => Configure::read('debug'),
            'route' => '/swagger/docs/',
            'cors' => [
                'Access-Control-Allow-Origin' => '*',
                'Access-Control-Allow-Methods' => 'GET, POST',
                'Access-Control-Allow-Headers' => 'X-Requested-With'
            ]
        ],
        'library' => [
            'api' => [
                'include' => ROOT . DS . 'src',
                'exclude' => [
                    '/Editor/'
                ]
            ],
            'editor' => [
                'include' => [
                    ROOT . DS . 'src' . DS . 'Controller' . DS . 'AppController.php',
                    ROOT . DS . 'src' . DS . 'Controller' . DS . 'Editor',
                    ROOT . DS . 'src' . DS . 'Model'
                ]
            ]
        ]
    ]
];

UI section

Use the ui section to customize the following Swagger-UI options:

  • title: sets the Swagger-UI page title, defaults to cakephp-swagger
  • validator: show/hide the validator image, defaults to true
  • api_selector: show/hide the api selector form fields, defaults to true
  • route: expose the UI using a custom route, defaults to /alt3/swagger/
  • schemes: array used to specify third field used to generate the BASE URL (host is fetched realtime, basePath is also fetched realtime if not defined via annotations), defaults to null

Please note that the UI will auto-load the first document found in the library.

Docs section

Use the docs section to customize the following options:

  • crawl: enable to crawl-generate new documents instead of serving from filesystem, defaults to true
  • route: expose the documents using a custom route, defaults to /alt3/swagger/docs/
  • cors: specify CORS headers to send with the json responses, defaults to null

Library section

Use the library section to specify one or multiple swagger documents so:

  • swagger-php will know which files and folders to parse for annotations
  • swagger-php can produce the swagger json
  • this plugin can expose the json at http://your.app/alt3/swagger/docs/:id (so it can be used by the UI)

The following library example would result in:

  • swagger-php scanning all files and folders defined in include
  • swagger-php ignoring all files and folders defined in exclude
  • two endpoints serving json swagger documents:
    • http://your.app/alt3/swagger/docs/api
    • http://your.app/alt3/swagger/docs/editor
'library' => [
    'api' => [
        'include' => ROOT . DS . 'src',
        'exclude' => [
            '/Editor/'
        ]
    ],
    'editor' => [
        'include' => [
            ROOT . DS . 'src' . DS . 'Controller' . DS . 'AppController.php',
            ROOT . DS . 'src' . DS . 'Controller' . DS . 'Editor',
            ROOT . DS . 'src' . DS . 'Model'
        ]
    ]
]

It would also make http://your.app/alt3/swagger/docs produce a json list with links to all available documents similar to the example below.

{
    "success": true,
    "data": [
        {
            "document": "api",
            "link": "http://your.app/alt3/swagger/docs/api"
        },
        {
            "document": "editor",
            "link": "http://your.app/alt3/swagger/docs/editor"
        }
    ]
}

SwaggerShell

This plugin comes with a shell that should simplify deployment in production environments. Simply run the following command to create cakephp_swagger prefixed filesystem documents in tmp/cache for all entities found in your library.

bin/cake swagger makedocs <host>

The host argument (e.g. your.app.com) is required, should not include protocols and is used to set the host property inside your swagger documents.

Quickstart Annotation Example

Explaining swagger-php annotation voodoo is beyond this plugin but to give yourself a head start while creating your first library document you might want to copy/paste the following working example into any of your php files.

Note: the weird non-starred syntax ensures compatibility with the CakePHP Code Sniffer.

<?php
/**
    @SWG\Swagger(
        @SWG\Info(
            title="cakephp-swagger",
            description="Quickstart annotation example",
            termsOfService="http://swagger.io/terms/",
            version="1.0.0"
        )
    )

    @SWG\Get(
        path="/cocktails",
        summary="Retrieve a list of cocktails",
        tags={"cocktail"},
        consumes={"application/json"},
        produces={"application/json"},
        @SWG\Parameter(
            name="sort",
            description="Sort results by field",
            in="query",
            required=false,
            type="string",
            enum={"name", "description"}
        ),
        @SWG\Response(
            response="200",
            description="Successful operation",
            @SWG\Schema(
                type="object",
                ref="#/definitions/Cocktail"
            )
        ),
        @SWG\Response(
            response=429,
            description="Rate Limit Exceeded"
        )
    )

    @SWG\Definition(
        definition="Cocktail",
        required={"name", "description"},
        @SWG\Property(
            property="id",
            type="integer",
            description="CakePHP record id"
        ),
        @SWG\Property(
            property="name",
            type="string",
            description="CakePHP name field"
        ),
        @SWG\Property(
            property="description",
            type="string",
            description="Description of a most tasty cocktail"
        )
    )
*/

Which should result in:

UI Quickstart Example

Additional Reading

Contribute

Before submitting a PR make sure:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].