Schemas and Read - Write Operations

Read and write operations; It includes Create - Read - Update - Delete operations.

Schemas

Schemas are simply designed to document the data to be sent and received to the API during write and read operations. Usually, when saving a record, the data manager class takes a reference from the schema class to ensure the existence of the relevant columns. A schema class consists of displaying the input names to be recorded in the database table or read from this table together with their types in a class.

  • Schemas can contain the following two complex types in addition to string, number and integer formats.
Type Description
array If this entity is a part of another entity of array type, you should select this type.
object If this entity is a part of another entity of object type, you should select this type.

Schemas Containing Objects

If we want to send data of type object in the http header, it should be written as employeePersonal object, as in the following example.

EmployeeSave (Instance with Object)

<?php
namespace App\Schema\Employees;

/**
 * @OA\Schema()
 */
class EmployeeSave
{
    /**
     * @var string
     * @OA\Property(
     *     format="uuid"
     * )
     */
    public $employeeId;
    /**
     * @var string
     * @OA\Property()
     */
    public $name;
    /**
     * @var string
     * @OA\Property()
     */
    public $surname;
    /**
    * @var object
    * @OA\Property(
    *     ref="#/components/schemas/EmployeePersonalObject",
    * )
    */
    public $employeePersonal;
}
{
  "employeeId": "string",
  "name": "string",
  "surname": "string",
  "employeePersonal": {
    "militaryStatusId": "string",
    "militaryStartDate": "string",
    "militaryEndDate": "string",
    "marialStatusId": "string"
  }
}
[
    "employeeId": "string",
    "name": "string",
    "surname": "string",
    "employeePersonal": [
        "militaryStatusId": "string",
        "militaryStartDate": "string",
        "militaryEndDate": "string",
        "marialStatusId": "string"
    ],
]

EmployeePersonalObject

<?php
namespace App\Schema\Employees;

/**
 * @OA\Schema()
 */
class EmployeePersonalObject
{
    /**
     * @var string
     * @OA\Property()
     */
    public $militaryStatusId;
    /**
     * @var string
     * @OA\Property(
     *     format="date",
     * )
     */
    public $militaryStartDate;
    /**
     * @var string
     * @OA\Property(
     *     format="date",
     * )
     */
    public $militaryEndDate;
    /**
     * @var string
     * @OA\Property()
     */
    public $marialStatusId;
}

Obtaining data with the data manager according to the EmployeesSave scheme.

$data = $this->dataManager->getSaveData(EmployeeSave::class, 'employees');
print_r($data);
/*
Array
(
    [employees] => Array
        (
            [name] => James
            [surname] => Brown
        ),
    [employeePersonal] => Array
        (
            [militaryStatusId] => discharge
            [militaryStartDate] => 2022-04-07
            [militaryEndDate] => 2022-04-18
            [marialStatusId] => married
        )
)
*/

Schemas Containing Strings

If we want to send data of array type in the http header, employeeChildren must be written as an array, as in the following example.

EmployeeSave (Example Containing an Array)

<?php
namespace App\Schema\Employees;

/**
 * @OA\Schema()
 */
class EmployeeSave
{
    /**
     * @var string
     * @OA\Property(
     *     format="uuid"
     * )
     */
    public $employeeId;
    /**
     * @var string
     * @OA\Property()
     */
    public $name;
    /**
     * @var string
     * @OA\Property()
     */
    public $surname;
    /**
    *  @var array
    *  @OA\Property(
    *      type="array",
    *      @OA\Items(
    *           @OA\Property(
    *             property="childId",
    *             type="string",
    *           ),
    *           @OA\Property(
    *             property="childName",
    *             type="string",
    *           ),
    *           @OA\Property(
    *             property="childBirthdate",
    *             type="string",
    *           ),
    *     ),
    *  );
    */
    public $employeeChildren;
}
This documents is available for subscribers only

Get Full Accesss