Skip to content

Latest commit

 

History

History
96 lines (71 loc) · 2.16 KB

File metadata and controls

96 lines (71 loc) · 2.16 KB

OpenApi

a module for Emvicy2 (2.x) PHP Framework: https://github.com/emvicy/Emvicy/tree/2.x


Installation

cd into the modules folder of your Emvicy copy; e.g.:

cd /var/www/html/modules/;

git clone

git clone --branch 3.x https://github.com/emvicy/OpenApi.git OpenApi;

Usage

validate against openapi file

use OpenApi\Model\Validate;

$oDTValidateRequestResponse = Validate::request(
    $oDTRequestCurrent,
    Config::get_MVC_PUBLIC_PATH() . '/openapi/api.yaml'
);

header('Content-Type: application/json');
echo json_encode(Convert::objectToArray($oDTValidateRequestResponse));

validate against openapi URL

use OpenApi\Model\Validate;

// validate against openapi URL
$oDTValidateRequestResponse = Validate::request(
    $oDTRequestCurrent,
    'https://example.com/api/openapi.yaml'
);

header('Content-Type: application/json');
echo json_encode(Convert::objectToArray($oDTValidateRequestResponse));

auto-creating Emvicy Routes from openapi file

All Routes lead to their given operationId, set in openapi

\OpenApi\Model\Route::autoCreateFromOpenApiFile(
    Config::get_MVC_PUBLIC_PATH() . '/openapi/api.yaml',
    '\Foo\Controller\Api'
);

All Routes lead explicitely to Api::delegate()

\OpenApi\Model\Route::autoCreateFromOpenApiFile(
    Config::get_MVC_PUBLIC_PATH() . '/openapi/api.yaml',
    '\Foo\Controller\Api',
    'delegate'
);

DTClassesOnOpenapi3yaml

\OpenApi\Model\Generate::DTClassesOnOpenapi3yaml(
    '/absolute/path/to/file/openapi.yaml',  # openapi yaml file | openapi yaml URL 
    'DTOpenapi',                            # Foldername; where to store DTClasses
    true,                                   # remove and create Folder for new; true|false
    false                                   # take values from "example" as default values
); 

Get Logs

Logs are fired to Events.

Available events are:

  • Emvicy_module_OpenApi::sYamlSource

listen to event and write its content to a logfile

\MVC\Event::bind('Emvicy_module_OpenApi::sYamlSource', function($sContent){
    \MVC\Log::write($sContent, 'openapi.log');
});