fiasco / tabular-openapi
Convert OpenAPI Schema into a relational table structure
Installs: 3 189
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- cebe/php-openapi: ^1.7
Requires (Dev)
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-11-12 03:30:21 UTC
README
Store OpenApi schema objects in tabular data structures.
This library allows you to map OpenApi schemas into tables that could be further converted into CSV, SQL or data lake storage (e.g. Domo).
Install
This library depends on cebe/php-openapi and can be installed with composer:
composer require fiasco/tabular-openapi
Usage
Load the schema
use Fiasco\TabularOpenapi\Schema; $schema = new Schema('https://path/to/openapi-spec.json');
Get an OpenApi schema component to insert data into.
$table = $schema->getTable('Report');
Insert your OpenApi compliant schema object into the table:
$table->addRow($report);
Loop over the schema tables to discover data in the tables. Tabular OpenApi has a dev dependency on Symfony Console so you can output tablular data to console during testing:
use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Style\SymfonyStyle; $io = new SymfonyStyle(new ArgvInput(), new ConsoleOutput()); foreach ($schema->getTables() as $name => $table) { $io->title($name.': '.$table->getRowsTotal() . ' ('.$table->uuid.')'); $rows = []; foreach ($table->fetchAll() as $row) { $rows[] = $row; } $headers = array_keys(reset($rows) ?: []); $io->table($headers, $rows); $io->text('----'); }