1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Console/Commands/OpenApiYaml.php

120 lines
3.7 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Console\Commands;
use DirectoryIterator;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
class OpenApiYaml extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ninja:openapi';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Build OpenApi YAML';
2023-02-12 12:14:53 +01:00
private array $directories = [
'/components/schemas',
'/paths/'
];
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$path = base_path('openapi');
$directory = new DirectoryIterator($path);
$this->info($directory);
foreach ($directory as $file) {
2023-02-16 02:36:09 +01:00
$this->info($file);
2023-02-12 08:58:00 +01:00
}
2024-01-14 05:05:00 +01:00
Storage::disk('base')->delete('/openapi/api-docs.yaml');
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/info.yaml'));
2023-02-12 12:14:53 +01:00
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/paths.yaml'));
//iterate paths
$directory = new DirectoryIterator($path . '/paths/');
foreach ($directory as $file) {
2023-02-16 02:36:09 +01:00
if ($file->isFile() && ! $file->isDot()) {
2023-02-12 12:14:53 +01:00
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents("{$path}/paths/{$file->getFilename()}"));
}
}
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/components.yaml'));
2023-02-18 05:08:56 +01:00
2023-07-08 12:16:09 +02:00
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/components/examples.yaml'));
2024-02-13 05:25:18 +01:00
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/components/responses.yaml'));
2023-02-18 05:08:56 +01:00
$directory = new DirectoryIterator($path . '/components/responses/');
foreach ($directory as $file) {
if ($file->isFile() && ! $file->isDot()) {
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents("{$path}/components/responses/{$file->getFilename()}"));
}
}
2023-02-18 09:58:40 +01:00
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/components/parameters.yaml'));
$directory = new DirectoryIterator($path . '/components/parameters/');
foreach ($directory as $file) {
if ($file->isFile() && ! $file->isDot()) {
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents("{$path}/components/parameters/{$file->getFilename()}"));
}
}
2023-02-12 08:58:00 +01:00
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/components/schemas.yaml'));
2023-02-12 12:14:53 +01:00
//iterate schemas
2024-01-14 05:05:00 +01:00
2023-02-12 12:14:53 +01:00
$directory = new DirectoryIterator($path . '/components/schemas/');
foreach ($directory as $file) {
2023-02-16 02:36:09 +01:00
if ($file->isFile() && ! $file->isDot()) {
2023-02-12 12:14:53 +01:00
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents("{$path}/components/schemas/{$file->getFilename()}"));
}
}
2023-02-18 05:08:56 +01:00
2023-02-12 12:14:53 +01:00
// Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/components/schemas/account.yaml'));
Storage::disk('base')->append('/openapi/api-docs.yaml', file_get_contents($path.'/misc/misc.yaml'));
}
}