- Add OpenApiDocs controller for serving bundled API docs - Split monolithic api-docs.yaml into modular components/ - Add organized paths/ directory with endpoint definitions - Create bundling scripts (JS, PHP, Python) for merging docs - Add API_DOCS_README.md with documentation guidelines - Update Routes.php for new API documentation endpoints - Update swagger.php view and TestDefSiteModel
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()
|
|
]));
|
|
}
|
|
}
|
|
}
|