PHP code example of alireza-h / php-openapi
1. Go to this page and download the library: Download alireza-h/php-openapi library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alireza-h / php-openapi example snippets
OpenApiBuilder::openapi()
->info(
[
'title' => 'API',
'description' => 'API Description',
'version' => '1.0.0'
]
)
->server(
[
'url' => '{scheme}://{host}/{base_path}',
'variables' => [
'scheme' => [
'enum' => [
'http',
'https'
],
'default' => 'http'
],
'host' => [
'default' => 'localhost:8000'
],
'base_path' => [
'default' => 'api'
],
]
]
)
->component(
'securitySchemes',
'bearerAuth',
[
'type' => 'http',
'scheme' => 'bearer',
'bearerFormat' => 'JWT',
]
)
->security(
[
'bearerAuth' => []
]
)
->operation(
OpenApiOperation::post('/auth/signup')
->tags(['Auth'])
->summary('Signup')
->description('Signup description')
->requestBody(
OpenApiRequestBody::create()
->properties(
[
[
'name' => 'email',
'type' => 'string',
'format' => 'email',
'example' => '[email protected]',
'description' => 'Email',
],
...
]
)
->mediaTypeMultipartFormData()
)
->response(
OpenApiResponse::create()
->example(
[
'data' => [],
'message' => null
]
)
)
)
->operation(
OpenApiOperation::put('/auth/confirm')
->tags(['Auth'])
->summary('ConfirmSignup')
->description('Confirm signup description')
->requestBody(
OpenApiRequestBody::create()
->properties(
[
[
'name' => 'email',
'type' => 'string',
'format' => 'email',
'example' => '[email protected]',
'description' => 'Email',
],
[
'name' => 'code',
'example' => 12345,
]
]
)
->mediaTypeXWwwFormUrlencoded()
)
->response(
OpenApiResponse::create()
->example(
[
'data' => [],
'message' => null
]
)
)
)
->docs();