noitran / opendox
OpenApi(Swagger) 3.0 package for Lumen 5.5+ and Laravel 5.5+ with REDOC UI and SwaggerUI 3
Installs: 12 549
Dependents: 0
Suggesters: 0
Security: 0
Stars: 21
Watchers: 1
Forks: 5
Open Issues: 1
Requires
- php: >=7.3
- ext-json: *
- illuminate/routing: ^5|^6|^7|^8
- symfony/yaml: ^5.0
Requires (Dev)
- illuminate/console: ^6.0|^7.0|^8.0
- illuminate/http: ^6.0|^7.0|^8.0
- illuminate/support: ^6.0|^7.0|^8.0
- laravel/lumen-framework: ~8.0
- orchestra/testbench: ^4.0|^5.0|^6.0
- phpunit/phpunit: ~7.0
This package is auto-updated.
Last update: 2024-10-22 00:47:27 UTC
README
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 noitran/opendox
Laravel
- Laravel uses provider auto discovery. Config file can be published using command
$ php artisan vendor:publish --provider="Noitran\Opendox\ServiceProvider"
Lumen
- Open your bootstrap/app.php and register as service provider
$app->register(Noitran\Opendox\ServiceProvider::class);
- Config file should be loaded manually in bootstrap/app.php
$app->configure('opendox');
Usage
- In your application project
/src
folder createapi-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