1. Go to this page and download the library: Download goldspecdigital/oooas library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
goldspecdigital / oooas example snippets
use GoldSpecDigital\ObjectOrientedOAS\Objects\{
Info, MediaType, Operation, PathItem, Response, Schema, Tag
};
use GoldSpecDigital\ObjectOrientedOAS\OpenApi;
// Create a tag for all the user endpoints.
$usersTag = Tag::create()
->name('Users')
->description('All user related endpoints');
// Create the info section.
$info = Info::create()
->title('API Specification')
->version('v1')
->description('For using the Example App API');
// Create the user schema.
$userSchema = Schema::object()
->properties(
Schema::string('id')->format(Schema::FORMAT_UUID),
Schema::string('name'),
Schema::integer('age')->example(23),
Schema::string('created_at')->format(Schema::FORMAT_DATE_TIME)
);
// Create the user response.
$userResponse = Response::create()
->statusCode(200)
->description('OK')
->content(
MediaType::json()->schema($userSchema)
);
// Create the operation for the route (i.e. GET, POST, etc.).
$showUser = Operation::get()
->responses($userResponse)
->tags($usersTag)
->summary('Get an individual user')
->operationId('users.show');
// Define the /users path along with the supported operations.
$usersPath = PathItem::create()
->route('/users')
->operations($showUser);
// Create the main OpenAPI object composed off everything created above.
$openApi = OpenApi::create()
->openapi(OpenApi::OPENAPI_3_0_2)
->info($info)
->paths($usersPath)
->tags($usersTag);
header('Content-Type: application/json');
echo $openApi->toJson();
use GoldSpecDigital\ObjectOrientedOAS\OpenApi;
use Symfony\Component\Yaml\Yaml;
$openApi = OpenApi::create();
$json = $openApi->toJson();
$array = $openApi->toArray();
$yaml = Yaml::dump($array);