PHP code example of amsify42 / php-swagger-postman
1. Go to this page and download the library: Download amsify42/php-swagger-postman 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/ */
amsify42 / php-swagger-postman example snippets
$attribute = new \Amsify42\PhpSwaggerPostman\Swagger\Attribute();
echo $attribute->generate();
$attribute->checkRules(
function ($name, $rule) use($attribute) {
if ($rule == 'array') {
return [
'property' => $attribute->createObjectOrArrayProperty(
$_POST[$name], // or $_GET[$name] or value from body data
$name
)
];
}
return NULL;
}
);
$attribute->setSecurity('XApiKey'); // The XApiKey will be from the security attribute already added
$attribute->setResponse([
[
'code' => 422,
'ref' => '#/components/responses/Validation' // Validation here is the name of response which is already defined somewhere
]
]);
#[OA\Response(
response: "Validation",
description: "Validation Errors",
content: new OA\JsonContent(
properties: [
new OA\Property(
property: "message",
example: "Please check the inputs provided"
),
new OA\Property(
property: "errors",
type: "object"
)
]
)
)]
$annotation = new \Amsify42\PhpSwaggerPostman\Swagger\Annotation();
echo $annotation->generate();
$swagger = new \Amsify42\PhpSwaggerPostman\Swagger;
$swagger->getGeneratedJson(
"path/to/scan-directory",
"path/to/export-swagger-and-postman-json/"
);
use OpenApi\Attributes as OA;
#[OA\Info(title: "My API", version: "1.0.0")]
#[OA\Get(path:"/api/users")]
#[OA\Response(response:"200", description:"An example endpoint")]