I’m using L5 Swagger in a Laravel project to generate OpenAPI documentation. I’ve written a custom command (app/Console/Commands/GenerateSwaggerAnnotations.php) that parses controller methods and generates basic @OA\RequestBody annotations. It works well for simple inputs, but I'm struggling to support nested request bodies, especially arrays of objects.
For example, from this structure in rules():
return [
'employee_id' => 'required|integer',
'destinations' => 'required|array',
'destinations.*.trip_destination_id' => 'required|integer',
'destinations.*.details' => 'array',
'destinations.*.details.*.trip_cost_category_id' => 'integer',
];
I’d like to generate this OpenAPI annotation automatically:
@OA\RequestBody(
required=true,
@OA\JsonContent(
required={"employee_id", "destinations"},
@OA\Property(property="employee_id", type="integer"),
@OA\Property(
property="destinations",
type="array",
@OA\Items(
@OA\Property(property="trip_destination_id", type="integer"),
@OA\Property(
property="details",
type="array",
@OA\Items(
@OA\Property(property="trip_cost_category_id", type="integer")
)
)
)
)
)
)
I'm trying to write a helper that parses the rules() method and builds this structure, but I'm stuck on how to interpret the . and * in keys like destinations.*.details.*.trip_cost_category_id.
How can I programmatically convert these kinds of rules into a correct nested OpenAPI schema?
Please note:
I'm limited to using L5 Swagger.
I can’t use Scribe or Scramble due to project restrictions.
I’m looking for a programmatic way to generate these annotations — not manual annotations.
Any guidance on how to properly parse the nested structure from rules() and generate the corresponding OpenAPI annotation would be appreciated.
Thanks!