This package reads an open api file (like swagger) and generates ready-to-use waffler interfaces.
Name | Version |
---|---|
Swagger | 2.0 |
Open Api | 3.0.x |
composer require waffler/opengen
** This package requires PHP 8 or above. **
<?php
require __DIR__.'/vendor/autoload.php';
use Waffler\OpenGen\ClientGenerator;
use \Waffler\OpenGen\Adapters\OpenApiV3Adapter;
$generator = new ClientGenerator(new OpenApiV3Adapter(
'FooBar\\Namespace',
));
$generationMap = $generator->generateFromYamlFile(
'path/to/openapi-file.yaml',
'path/to/output-dir/',
);
Adding this option, you can modify the ClientInterface
interface suffix.
- Type:
string
Example code:
[
'interface_suffix' => 'Api' // Replaces 'ClientInterface'
]
Adding this option, you can specify elements to ignore in the code generation. Available items to ignore are:
parameters
methods
Example code:
[
'ignore' => [
'parameters' => [],
'methods' => []
]
]
Adding this option, you can specify which parameter types you want to ignore in the code generation. Available parameter types are:
header
query
path
formData
Example code:
[
'ignore' => [
'parameters' => [
'header' => ['Authorization', 'other_header_name']
]
]
]
Adding this option, you can specify which method names you want to ignore in the code generation.
The method names are the operationId
in openapi spec files.
Example code:
[
'ignore' => [
'methods' => ['getById', 'deleteUser']
]
]
Adding this option, you can remove the prefix of operationIds from code generation. In the example below, we`ll
Example code:
[
'remove_method_prefix' => '/\w*\//'
]