44 lines
1.5 KiB
PHP
44 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Controllers;
|
||
|
|
|
||
|
|
class OpenApiDocs extends BaseController
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Serve pre-bundled OpenAPI specification
|
||
|
|
* Returns the bundled file with all paths and schemas resolved
|
||
|
|
*/
|
||
|
|
public function index()
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
// Load pre-bundled OpenAPI spec
|
||
|
|
$bundledPath = FCPATH . 'api-docs.bundled.yaml';
|
||
|
|
|
||
|
|
if (!file_exists($bundledPath)) {
|
||
|
|
throw new \Exception("Bundled API docs not found: api-docs.bundled.yaml. Run: node bundle-api-docs.js");
|
||
|
|
}
|
||
|
|
|
||
|
|
$content = file_get_contents($bundledPath);
|
||
|
|
|
||
|
|
// Output as YAML
|
||
|
|
return $this->response
|
||
|
|
->setContentType('application/x-yaml')
|
||
|
|
->setHeader('Access-Control-Allow-Origin', '*')
|
||
|
|
->setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS')
|
||
|
|
->setHeader('Access-Control-Allow-Headers', 'Content-Type')
|
||
|
|
->setHeader('Cache-Control', 'no-cache, must-revalidate')
|
||
|
|
->setBody($content);
|
||
|
|
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
log_message('error', 'OpenApiDocs Error: ' . $e->getMessage());
|
||
|
|
return $this->response
|
||
|
|
->setStatusCode(500)
|
||
|
|
->setContentType('application/json')
|
||
|
|
->setBody(json_encode([
|
||
|
|
'error' => 'Failed to serve OpenAPI spec',
|
||
|
|
'message' => $e->getMessage()
|
||
|
|
]));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|