upgrade: Laravel 13 + swagger-php v6 attributes

This commit is contained in:
parsa aghaei 2026-06-28 12:01:32 +03:30
parent f7ad5f6844
commit b31b4d73ac
8 changed files with 2253 additions and 1468 deletions

View File

@ -1,85 +1,95 @@
<?php <?php
/** namespace App;
* @OA\Info(
* title="Parsa Aghayi Portfolio API", use OpenApi\Attributes as OA;
* version="1.0.0",
* description="REST API for Parsa Aghayi's personal portfolio and blog" #[OA\Info(
* ) title: 'Parsa Aghayi Portfolio API',
* version: '1.0.0',
* @OA\Server( description: 'REST API for Parsa Aghayi\'s personal portfolio and blog'
* url="http://localhost:8000/api", )]
* description="Development server" #[OA\Server(
* ) url: 'http://localhost:8000/api',
* @OA\Server( description: 'Development server'
* url="https://backend.parsaaghayi.ir/api", )]
* description="Production server" #[OA\Server(
* ) url: 'https://backend.parsaaghayi.ir/api',
* description: 'Production server'
* @OA\Schema( )]
* schema="Skill", #[OA\Schema(
* type="object", schema: 'Skill',
* @OA\Property(property="id", type="integer"), type: 'object',
* @OA\Property(property="title", type="string"), properties: [
* @OA\Property(property="description", type="string"), new OA\Property(property: 'id', type: 'integer'),
* @OA\Property(property="image", type="string"), new OA\Property(property: 'title', type: 'string'),
* @OA\Property(property="link", type="string", nullable=true), new OA\Property(property: 'description', type: 'string'),
* @OA\Property(property="percentage", type="integer") new OA\Property(property: 'image', type: 'string'),
* ) new OA\Property(property: 'link', type: 'string', nullable: true),
* new OA\Property(property: 'percentage', type: 'integer'),
* @OA\Schema( ]
* schema="AboutMe", )]
* type="object", #[OA\Schema(
* @OA\Property(property="id", type="integer"), schema: 'AboutMe',
* @OA\Property(property="title", type="string"), type: 'object',
* @OA\Property(property="description", type="string"), properties: [
* @OA\Property(property="image", type="string"), new OA\Property(property: 'id', type: 'integer'),
* @OA\Property(property="skills", type="array", @OA\Items(ref="#/components/schemas/Skill")) new OA\Property(property: 'title', type: 'string'),
* ) new OA\Property(property: 'description', type: 'string'),
* new OA\Property(property: 'image', type: 'string'),
* @OA\Schema( new OA\Property(property: 'skills', type: 'array', items: new OA\Items(ref: '#/components/schemas/Skill')),
* schema="Service", ]
* type="object", )]
* @OA\Property(property="id", type="integer"), #[OA\Schema(
* @OA\Property(property="imageSrc", type="string"), schema: 'Service',
* @OA\Property(property="altText", type="string"), type: 'object',
* @OA\Property(property="title", type="string"), properties: [
* @OA\Property(property="description", type="string"), new OA\Property(property: 'id', type: 'integer'),
* @OA\Property(property="created_at", type="string", format="datetime"), new OA\Property(property: 'imageSrc', type: 'string'),
* @OA\Property(property="updated_at", type="string", format="datetime") new OA\Property(property: 'altText', type: 'string'),
* ) new OA\Property(property: 'title', type: 'string'),
* new OA\Property(property: 'description', type: 'string'),
* @OA\Schema( new OA\Property(property: 'created_at', type: 'string', format: 'datetime'),
* schema="Project", new OA\Property(property: 'updated_at', type: 'string', format: 'datetime'),
* type="object", ]
* @OA\Property(property="id", type="integer"), )]
* @OA\Property(property="title", type="string"), #[OA\Schema(
* @OA\Property(property="category", type="string", nullable=true), schema: 'Project',
* @OA\Property(property="images", type="array", @OA\Items(type="object")), type: 'object',
* @OA\Property(property="created_at", type="string", format="datetime"), properties: [
* @OA\Property(property="updated_at", type="string", format="datetime") new OA\Property(property: 'id', type: 'integer'),
* ) new OA\Property(property: 'title', type: 'string'),
* new OA\Property(property: 'category', type: 'string', nullable: true),
* @OA\Schema( new OA\Property(property: 'images', type: 'array', items: new OA\Items(type: 'object')),
* schema="Category", new OA\Property(property: 'created_at', type: 'string', format: 'datetime'),
* type="object", new OA\Property(property: 'updated_at', type: 'string', format: 'datetime'),
* @OA\Property(property="id", type="integer"), ]
* @OA\Property(property="title", type="string"), )]
* @OA\Property(property="image", type="string") #[OA\Schema(
* ) schema: 'Category',
* type: 'object',
* @OA\Schema( properties: [
* schema="Post", new OA\Property(property: 'id', type: 'integer'),
* type="object", new OA\Property(property: 'title', type: 'string'),
* @OA\Property(property="id", type="integer"), new OA\Property(property: 'image', type: 'string'),
* @OA\Property(property="title", type="string"), ]
* @OA\Property(property="body", type="string"), )]
* @OA\Property(property="excerpt", type="string"), #[OA\Schema(
* @OA\Property(property="slug", type="string"), schema: 'Post',
* @OA\Property(property="featured_image", type="string", nullable=true), type: 'object',
* @OA\Property(property="author", type="object"), properties: [
* @OA\Property(property="category", type="object"), new OA\Property(property: 'id', type: 'integer'),
* @OA\Property(property="tags", type="array", @OA\Items(type="object")), new OA\Property(property: 'title', type: 'string'),
* @OA\Property(property="published_at", type="string", format="datetime", nullable=true) new OA\Property(property: 'body', type: 'string'),
* ) new OA\Property(property: 'excerpt', type: 'string'),
*/ new OA\Property(property: 'slug', type: 'string'),
new OA\Property(property: 'featured_image', type: 'string', nullable: true),
new OA\Property(property: 'author', type: 'object'),
new OA\Property(property: 'category', type: 'object'),
new OA\Property(property: 'tags', type: 'array', items: new OA\Items(type: 'object')),
new OA\Property(property: 'published_at', type: 'string', format: 'datetime', nullable: true),
]
)]
class SwaggerDefinitions
{
}

View File

@ -0,0 +1,15 @@
<?php
namespace App;
use L5Swagger\CustomGeneratorInterface;
use OpenApi\Generator as OpenApiGenerator;
use Psr\Log\NullLogger;
class SwaggerGeneratorFactory implements CustomGeneratorInterface
{
public function create(): OpenApiGenerator
{
return new OpenApiGenerator(new NullLogger());
}
}

View File

@ -6,10 +6,10 @@
"license": "MIT", "license": "MIT",
"require": { "require": {
"php": "^8.2", "php": "^8.2",
"darkaonline/l5-swagger": "^9.0", "darkaonline/l5-swagger": "^11.0",
"laravel/framework": "^11.9", "laravel/framework": "^13.0",
"laravel/sanctum": "^4.0", "laravel/sanctum": "^4.0",
"laravel/tinker": "^2.9", "laravel/tinker": "^3.0",
"spatie/laravel-translatable": "^6.14" "spatie/laravel-translatable": "^6.14"
}, },
"require-dev": { "require-dev": {
@ -18,7 +18,7 @@
"laravel/sail": "^1.26", "laravel/sail": "^1.26",
"mockery/mockery": "^1.6", "mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.0", "nunomaduro/collision": "^8.0",
"phpunit/phpunit": "^11.0.1" "phpunit/phpunit": "^12.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

3329
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -17,6 +17,8 @@
'default' => env('CACHE_STORE', 'database'), 'default' => env('CACHE_STORE', 'database'),
'serializable_classes' => false,
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Cache Stores | Cache Stores

View File

@ -102,6 +102,14 @@
], ],
'scanOptions' => [ 'scanOptions' => [
/**
* Use a custom generator factory that suppresses swagger-php warnings
* (which get converted to ErrorException by Laravel).
*
* @see \OpenApi\Generator
*/
'generator_factory' => \App\SwaggerGeneratorFactory::class,
/** /**
* Configuration for default processors. Allows to pass processors configuration to swagger-php. * Configuration for default processors. Allows to pass processors configuration to swagger-php.
* *

View File

@ -77,7 +77,7 @@
'middleware' => [ 'middleware' => [
'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class, 'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class,
'encrypt_cookies' => Illuminate\Cookie\Middleware\EncryptCookies::class, 'encrypt_cookies' => Illuminate\Cookie\Middleware\EncryptCookies::class,
'validate_csrf_token' => Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class, 'validate_csrf_token' => Illuminate\Foundation\Http\Middleware\PreventRequestForgery::class,
], ],
]; ];

View File

@ -0,0 +1,181 @@
{
"openapi": "3.0.0",
"info": {
"title": "Parsa Aghayi Portfolio API",
"description": "REST API for Parsa Aghayi's personal portfolio and blog",
"version": "1.0.0"
},
"servers": [
{
"url": "http://localhost:8000/api",
"description": "Development server"
},
{
"url": "https://backend.parsaaghayi.ir/api",
"description": "Production server"
}
],
"components": {
"schemas": {
"Skill": {
"properties": {
"id": {
"type": "integer"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"image": {
"type": "string"
},
"link": {
"type": "string",
"nullable": true
},
"percentage": {
"type": "integer"
}
},
"type": "object"
},
"AboutMe": {
"properties": {
"id": {
"type": "integer"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"image": {
"type": "string"
},
"skills": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Skill"
}
}
},
"type": "object"
},
"Service": {
"properties": {
"id": {
"type": "integer"
},
"imageSrc": {
"type": "string"
},
"altText": {
"type": "string"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"created_at": {
"type": "string",
"format": "datetime"
},
"updated_at": {
"type": "string",
"format": "datetime"
}
},
"type": "object"
},
"Project": {
"properties": {
"id": {
"type": "integer"
},
"title": {
"type": "string"
},
"category": {
"type": "string",
"nullable": true
},
"images": {
"type": "array",
"items": {
"type": "object"
}
},
"created_at": {
"type": "string",
"format": "datetime"
},
"updated_at": {
"type": "string",
"format": "datetime"
}
},
"type": "object"
},
"Category": {
"properties": {
"id": {
"type": "integer"
},
"title": {
"type": "string"
},
"image": {
"type": "string"
}
},
"type": "object"
},
"Post": {
"properties": {
"id": {
"type": "integer"
},
"title": {
"type": "string"
},
"body": {
"type": "string"
},
"excerpt": {
"type": "string"
},
"slug": {
"type": "string"
},
"featured_image": {
"type": "string",
"nullable": true
},
"author": {
"type": "object"
},
"category": {
"type": "object"
},
"tags": {
"type": "array",
"items": {
"type": "object"
}
},
"published_at": {
"type": "string",
"format": "datetime",
"nullable": true
}
},
"type": "object"
}
}
}
}