Generation schemas

Package supported schemas openapi. For more details about schema see documentationopen in new window.

Base example

For base schema need define properties attributes. This can be a bit tedious, but it gives you full control over your schema. An alternative approach is to use ModelSchema.

use OpenApiGenerator\Attributes\Property\Str;
use OpenApiGenerator\Attributes\Property\Number;

#[
    Info('test'),
    Schema('personalDataSchema'),
    Str('name'),
    Str('phone'),
    Number('age'),
]
class SimpleSchema
{
    //
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Model Schema

use OpenApiGenerator\Attributes\Property\Number;
use OpenApiGenerator\Attributes\Schema\Model;

#[Schema(model: true)]
// or
#[Model]
class SchemaModel
{
    public string $title;
    public bool $is_banned;
    public float $price;

    // property can override type, name, format and add new info.
    #[Property(
        description: 'The age of person',
        example: 123,
        format: 'int32',
    )]
    public int $age;
    
    // or
    #[Number(
        description: 'The age of person',
        example: 123,
        format: 'int32',
    )]
    public $ageAlt;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Last Updated: 10/10/2021, 7:14:06 PM
Contributors: AkioSarkiz