io-digital/opendox

OpenApi(Swagger) 3.0 package for Laravel 9 with REDOC UI and SwaggerUI 3

1.0 2022-12-06 14:50 UTC

This package is auto-updated.

Last update: 2024-12-06 19:30:40 UTC


README

Software License Latest Version Total Downloads

About

This package will add console command to lumen/laravel which will parse yml file, convert it into json and save to public path. Redoc UI is connected and Swagger UI are connected and can be accessed to view generated documentation. Also package adds route for raw json documentation output, so this package can be used in microservice architecture, where all your microservices expose list of available routes.

Features

  • Adds console command php artisan opendox:transform to transform OpenApi 3.0 specification yaml files to json, so it can be accessible for external services
  • Adds /api/documentation route where you can access Redoc UI interface of documentation
  • Adds /api/console route where you can access Swagger UI interface for API docs and interaction
  • Adds /docs route where RAW json can be accessed

Install

  • Install as composer package
$ composer require io-digital/opendox

Laravel

  • Laravel uses provider auto discovery. Config file can be published using command
$ php artisan vendor:publish --provider="IoDigital\Opendox\ServiceProvider"

Lumen

  • Open your bootstrap/app.php and register as service provider
$app->register(IoDigital\Opendox\ServiceProvider::class);
  • Config file should be loaded manually in bootstrap/app.php
$app->configure('opendox');

Usage

  • In your application project /src folder create api-docs.yml file. Write your documentation using OpenAPI standard

Example

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: limit
          in: query
          description: How many items to return at one time (max 100)
          required: false
          schema:
            type: integer
            format: int32
      responses:
        '200':
          description: A paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pets"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
components:
  schemas:
    Pet:
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
    Pets:
      type: array
      items:
        $ref: "#/components/schemas/Pet"
    Error:
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
  • Transform and publish your configuration file using command
$ php artisan opendox:transform
  • Now your documentation is accessible via specified routes:
/api/documentation - Redoc UI interface

/api/console - Swagger UI with ability to send example requests

/docs - Raw JSON documentation output, that can be used for external services