Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to document php api with swagger

1. Install with composer:#
> composer require --dev zircote/swagger-php

2. Update your code#
Add swagger-php annotations or attributes to your source code.

Annotations
Attributes
<?php

use OpenApiAnnotations as OA;

/**
 * @OAInfo(
 *     title="My First API",
 *     version="0.1"
 * )
 */
class OpenApi {}

class MyController {

    /**
     * @OAGet(
     *     path="/api/data.json",
     *     @OAResponse(
     *         response="200",
     *         description="The data"
     *     )
     * )
     */
    public function getResource() {
        // ...
    }
}

3. Generate OpenAPI documentation#
> ./bin/openapi src -o openapi.yaml

4. Explore and interact with your API#
Use an OpenAPI tool like Swagger UI to explore and interact with your API.
Comment

PREVIOUS NEXT
Code Example
Php :: Your Composer dependencies require the following PHP extensions to be installed: curl 
Php :: php get query params 
Php :: wordpress get user by id 
Php :: guzzlehttp php basic auth 
Php :: run raw sql with doctrine manager 
Php :: how get year of field database in laravel collection 
Php :: migrate to an existing table in laravel commad 
Php :: counting time execution duration in time laravel 
Php :: php chunk array 
Php :: insert timestamps manually in laravel 
Php :: phpunit stop on failure 
Php :: Carbon Add Months To Date In Laravel 
Php :: file_get_contents url fail 
Php :: laravel migration remove constraint 
Php :: laravel blade get authenticated user email 
Php :: php sort array by key 
Php :: in loop how add string by comma in php 
Php :: blade formatting vscode 
Php :: check file selected in php 
Php :: laravel limit query pagination 
Php :: laravel eloquent get last record 
Php :: php post 
Php :: curl exec not working php 
Php :: php trim string to length 
Php :: wordpress get post slug 
Php :: php find text in variable 
Php :: explode in php 
Php :: php __construct 
Php :: php replace every occurrence of character in string 
Php :: laravel join 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =