PHP code example of uderline / openapi-php-attributes
1. Go to this page and download the library: Download uderline/openapi-php-attributes 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/ */
uderline / openapi-php-attributes example snippets
#[Controller]
class Controller {
#[
GET("/path/{id}", ["Tag1", "Tag2"], "Description of the method"),
Property(Type::STRING, "prop1", description: "Property description", enum: BackedEnum::class),
Property(Type::INT, "prop2", example: 1),
Property(Type::BOOLEAN, "prop3"),
Property(Type::REF, "prop4", ref: RefSchema::class)
Response(ref: SchemaName::class, description: "Response description")
]
public function get(#[Parameter("Parameter description")] int $id): JsonResponse {
// ...
}
}
enum BackedEnum: string
{
case VAL1: "val1";
case VAL2: "val2";
}
#[
Schema,
Property(Type::STRING, "Property 1"),
Property(Type::INT, "Property 2"),
]
class RefSchema
{
public string $property1;
public int $property2;
}