jane/openapi-runtime
Deprecated runtime package for Jane OpenAPI. This repository is no longer maintained; development has moved to the main janephp/janephp project. Use that repo for current OpenAPI runtime components and updates.
Installation (if still needed for legacy projects):
composer require jane/openapi-runtime
Note: This package is deprecated; verify if your project absolutely requires it or migrate to janephp/janephp.
First Use Case:
use Jane\OpenApiRuntime\Client;
$client = new Client('path/to/openapi.yaml');
$response = $client->get('/path/to/endpoint');
Key Files:
src/Client.php for core functionality.tests/ for usage examples (if available).API Client Initialization:
// In a Laravel service provider (e.g., AppServiceProvider)
public function register()
{
$this->app->singleton('openapi.client', function ($app) {
return new \Jane\OpenApiRuntime\Client(config('openapi.spec_path'));
});
}
Request Handling:
public function __construct(private Client $openApiClient) {}
public function fetchData()
{
$response = $this->openApiClient->get('/users');
return json_decode($response->getBody(), true);
}
Middleware Integration:
$client->setDefaultOption('headers', [
'Authorization' => 'Bearer ' . auth()->token(),
]);
Response Processing:
$data = $response->getBody();
return response()->json($data);
Deprecation Warning:
zircote/swagger-phpIlluminate\Support\Facades\Http).No Laravel-Specific Features:
Outdated PSR Standards:
Psr\Http\Message interfaces). Use adapters if needed:
use GuzzleHttp\Psr7\Utils;
$body = Utils::streamFor($response->getBody());
Enable Verbose Logging:
$client->setDefaultOption('debug', true);
Validate OpenAPI Spec:
Error Handling:
try {
$response = $client->post('/endpoint', ['data' => $payload]);
} catch (\Jane\OpenApiRuntime\Exception\RuntimeException $e) {
Log::error('OpenAPI Error: ' . $e->getMessage());
return response()->json(['error' => 'Service unavailable'], 503);
}
Custom Middleware:
Jane\OpenApiRuntime\Middleware\MiddlewareInterface to add logic (e.g., rate limiting):
class LaravelAuthMiddleware implements MiddlewareInterface {
public function __invoke($request, $next) {
$request->setHeader('X-Laravel-Token', auth()->token());
return $next($request);
}
}
Response Transformers:
class LaravelClient extends \Jane\OpenApiRuntime\Client {
protected function parseResponse($response) {
return json_decode($response->getBody(), true);
}
}
Caching:
$client = Cache::remember('openapi.client', 86400, function() {
return new Client(config('openapi.spec_path'));
});
How can I help you explore Laravel packages today?