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 @@
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use OpenApi\Attributes as OA;
class TeamController extends Controller
{
@ -27,6 +28,9 @@ private function removeSensitiveData($team)
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 @@ public function teams(Request $request)
);
}
#[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;

View File

@ -43,7 +43,8 @@
"stripe/stripe-php": "^12.0",
"symfony/yaml": "^6.2",
"visus/cuid2": "^2.0.0",
"yosymfony/toml": "^1.0"
"yosymfony/toml": "^1.0",
"zircote/swagger-php": "^4.10"
},
"require-dev": {
"fakerphp/faker": "^v1.21.0",

83
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "168e351cec87acbea9c1c745b83eead2",
"content-hash": "ec2082fff21212c016bfd6ffd13f8249",
"packages": [
{
"name": "amphp/amp",
@ -12348,6 +12348,87 @@
}
],
"time": "2023-05-30T22:51:52+00:00"
},
{
"name": "zircote/swagger-php",
"version": "4.10.3",
"source": {
"type": "git",
"url": "https://github.com/zircote/swagger-php.git",
"reference": "ad3f913d39b2a4dfb6e59ee4babb35a6b4a2b998"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zircote/swagger-php/zipball/ad3f913d39b2a4dfb6e59ee4babb35a6b4a2b998",
"reference": "ad3f913d39b2a4dfb6e59ee4babb35a6b4a2b998",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": ">=7.2",
"psr/log": "^1.1 || ^2.0 || ^3.0",
"symfony/deprecation-contracts": "^2 || ^3",
"symfony/finder": ">=2.2",
"symfony/yaml": ">=3.3"
},
"require-dev": {
"composer/package-versions-deprecated": "^1.11",
"doctrine/annotations": "^1.7 || ^2.0",
"friendsofphp/php-cs-fixer": "^2.17 || ^3.47.1",
"phpstan/phpstan": "^1.6",
"phpunit/phpunit": ">=8",
"vimeo/psalm": "^4.23"
},
"suggest": {
"doctrine/annotations": "^1.7 || ^2.0"
},
"bin": [
"bin/openapi"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.x-dev"
}
},
"autoload": {
"psr-4": {
"OpenApi\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Robert Allen",
"email": "zircote@gmail.com"
},
{
"name": "Bob Fanger",
"email": "bfanger@gmail.com",
"homepage": "https://bfanger.nl"
},
{
"name": "Martin Rademacher",
"email": "mano@radebatz.net",
"homepage": "https://radebatz.net"
}
],
"description": "swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations",
"homepage": "https://github.com/zircote/swagger-php/",
"keywords": [
"api",
"json",
"rest",
"service discovery"
],
"support": {
"issues": "https://github.com/zircote/swagger-php/issues",
"source": "https://github.com/zircote/swagger-php/tree/4.10.3"
},
"time": "2024-07-04T07:53:11+00:00"
}
],
"packages-dev": [

55
openapi.yaml Normal file
View File

@ -0,0 +1,55 @@
openapi: 3.0.0
info:
title: Coolify
version: '0.1'
servers:
-
url: 'https://coolify.io/api/v1'
paths:
/teams:
get:
operationId: f9c530b5b25df9601cb87d6a58646f0a
responses:
'200':
description: 'List of teams'
'401':
description: Unauthorized
'/teams/{id}':
get:
operationId: ac57ff546c002032cef44602c46a4e76
parameters:
-
name: id
in: path
description: 'Team ID'
required: true
schema:
type: integer
responses:
'401':
description: Unauthorized
content:
application/json:
schema:
properties:
message: { type: string, example: Unauthenticated. }
type: object
'404':
description: 'Team not found'
'200':
description: 'Team model'
content:
application/json:
schema:
properties:
id: { type: integer, example: 1 }
name: { type: string, example: 'Team 1' }
created_at: { type: string, format: date-time, example: '2021-10-10T10:00:00Z' }
updated_at: { type: string, format: date-time, example: '2021-10-10T10:00:00Z' }
type: object
components:
securitySchemes:
bearerAuth:
type: http
bearerFormat: JWT
scheme: bearer