Skip to content

gueff/myMVC_module_OpenApi

Repository files navigation

myMVC_module_OpenApi

Requirements


Installation

git clone

cd /modules/;

git clone --branch 1.x \
https://github.com/gueff/myMVC_module_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 myMVC 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'
);

Get Logs

Logs are fired to Events.

Available events are:

  • myMVC_module_OpenApi::sYamlSource

listen to event and write its content to a logfile

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