test openapi

This commit is contained in:
Andras Bacsai
2024-07-05 16:08:01 +02:00
parent 479a3540ec
commit 88ab385100
5 changed files with 186 additions and 2 deletions

View File

@@ -0,0 +1,16 @@
<?php
namespace App\Http\Controllers\Api;
use OpenApi\Attributes as OA;
#[OA\Info(title: 'Coolify', version: '0.1')]
#[OA\Server(url: 'https://coolify.io/api/v1')]
#[OA\SecurityScheme(type: 'http', scheme: 'bearer', bearerFormat: 'JWT', securityScheme: 'bearerAuth')]
class OpenApi
{
// This class is used to generate OpenAPI documentation
// for the Coolify API. It is not a controller and does
// not contain any routes. It is used to define the
// OpenAPI metadata and security scheme for the API.
}

View File

@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use OpenApi\Attributes as OA;
class TeamController extends Controller
{
@@ -27,6 +28,9 @@ class TeamController extends Controller
return serializeApiResponse($team);
}
#[OA\Get(path: '/teams')]
#[OA\Response(response: '200', description: 'List of teams')]
#[OA\Response(response: '401', description: 'Unauthorized')]
public function teams(Request $request)
{
$teamId = getTeamIdFromToken();
@@ -43,6 +47,33 @@ class TeamController extends Controller
);
}
#[OA\Get(path: '/teams/{id}')]
#[OA\Response(
response: 401,
description: 'Unauthorized',
content: new OA\JsonContent(
type: 'object',
properties: [
new OA\Property(property: 'message', type: 'string', example: 'Unauthenticated.'),
]
)
)]
#[OA\Response(response: '404', description: 'Team not found')]
#[OA\Parameter(name: 'id', in: 'path', required: true, description: 'Team ID', schema: new OA\Schema(type: 'integer'))]
// response 200 with team model
#[OA\Response(
response: 200,
description: 'Team model',
content: new OA\JsonContent(
type: 'object',
properties: [
new OA\Property(property: 'id', type: 'integer', example: 1),
new OA\Property(property: 'name', type: 'string', example: 'Team 1'),
new OA\Property(property: 'created_at', type: 'string', format: 'date-time', example: '2021-10-10T10:00:00Z'),
new OA\Property(property: 'updated_at', type: 'string', format: 'date-time', example: '2021-10-10T10:00:00Z'),
]
)
)]
public function team_by_id(Request $request)
{
$id = $request->id;