GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Swagger-PHP
  • User Guide
  • Reference
  • OpenApi
  • Releases

This view

  • Original page
  • New address

GeezerVison is showing zircote.com — Swagger-PHP

Skip to content

Swagger-PHP

Generate OpenAPI documentation for your RESTful API.

User Guide →

OpenAPI conformant

Generate OpenAPI documents in version 3.0, 3.1 or 3.2.

Document your API inside PHP source code

Using swagger-php lets you write the API documentation inside the PHP source files which helps keeping the documentation up-to-date.

Typed attributes

Attributes are PHP objects that can also be built by hand, and the pipeline reports when one is wrong.

1. Install with composer: ​

shell
> composer require zircote/swagger-php

2. Update your code ​

Add swagger-php attributes to your source code.

php
<?php

namespace Openapi\Snippets\MinimalApi;

use OpenApi\Spec as OA;

#[OA\Info(title: 'My First API', version: '0.1')]
class OpenApi
{
}

class MyController
{
    #[OA\Operation\Get(path: '/api/data.json', operationId: 'getData')]
    #[OA\Response(response: '200', description: 'The data')]
    public function getResource()
    {
        // ...
    }
}
php
<?php

namespace Openapi\Snippets\MinimalApi;

use OpenApi\Attributes as OA;

#[OA\Info(title: 'My First API', version: '0.1')]
class OpenApi
{
}

class MyController
{
    #[OA\Get(path: '/api/data.json', operationId: 'getData')]
    #[OA\Response(response: '200', description: 'The data')]
    public function getResource()
    {
        // ...
    }
}
php
<?php

namespace Openapi\Snippets\MinimalApi;

use OpenApi\Annotations as OA;

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

class MyController
{
    /**
     * @OA\Get(
     *     path="/api/data.json",
     *     operationId="getData",
     *     @OA\Response(
     *         response="200",
     *         description="The data"
     *     )
     * )
     */
    public function getResource()
    {
        // ...
    }
}

3. Generate OpenAPI documentation ​

shell
> ./vendor/bin/openapi src -o openapi.yaml

4. Explore and interact with your API ​

Use an OpenAPI tool like Swagger UI or Scalar to explore and interact with your API.

Links ​

  • User Guide
  • Reference
  • OpenApi Documentation
  • OpenApi Specification
  • Learn by example
  • Related projects
  • swagger-php 2.x documentation
  • swagger-php 3.x documentation
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.