Skip to content

Commit

Permalink
refactor: Update swagger documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
octfx committed May 3, 2024
1 parent 473d81a commit 374c1d9
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 113 deletions.
10 changes: 3 additions & 7 deletions app/Http/Controllers/Api/V2/AbstractApiV2Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ enum: [
enum: [
'shops',
'shops.items',
'variants',
]
),
),
Expand Down Expand Up @@ -138,7 +139,7 @@ abstract class AbstractApiV2Controller extends Controller
/**
* AbstractApiController constructor.
*
* @param Request $request API Request
* @param Request $request API Request
*/
public function __construct(Request $request)
{
Expand Down Expand Up @@ -184,15 +185,13 @@ private function processLimit(): void
*/
private function processLocale(): void
{
if ($this->request->has(self::LOCALE) && null !== $this->request->get(self::LOCALE, null)) {
if ($this->request->has(self::LOCALE) && $this->request->get(self::LOCALE, null) !== null) {
$this->setLocale($this->request->get(self::LOCALE));
}
}

/**
* Set the Locale
*
* @param string $localeCode
*/
protected function setLocale(string $localeCode): void
{
Expand All @@ -204,9 +203,6 @@ protected function setLocale(string $localeCode): void

/**
* Cleans the name for query use
*
* @param string $name
* @return string
*/
protected function cleanQueryName(string $name): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CommLinkController extends AbstractApiV2Controller
type: 'array',
items: new OA\Items(ref: '#/components/schemas/comm_link_v2')
)
)
),
]
)]
public function index(): AnonymousResourceCollection
Expand Down Expand Up @@ -95,14 +95,14 @@ public function index(): AnonymousResourceCollection
],
responses: [
new OA\Response(
ref: '#/components/schemas/comm_link_v2',
response: 200,
description: 'A singular Comm-Link',
content: new OA\JsonContent(ref: '#/components/schemas/comm_link_v2')
),
new OA\Response(
response: 404,
description: 'No Comm-Link with specified ID found.',
)
),
]
)]
public function show(Request $request): AbstractBaseResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CommLinkSearchController extends AbstractApiV2Controller
type: 'object',
),
example: '{"query": "Banu Merchantman"}',
)
),
]
),
tags: ['Comm-Links', 'RSI-Website'],
Expand All @@ -51,14 +51,14 @@ class CommLinkSearchController extends AbstractApiV2Controller
],
responses: [
new OA\Response(
ref: '#/components/schemas/comm_link_v2',
response: 200,
description: 'A singular Comm-Link',
content: new OA\JsonContent(ref: '#/components/schemas/comm_link_v2')
),
new OA\Response(
response: 404,
description: 'No Comm-Link with found.',
)
),
],
)]
public function searchByTitle(Request $request): AnonymousResourceCollection
Expand Down Expand Up @@ -94,7 +94,7 @@ public function searchByTitle(Request $request): AnonymousResourceCollection
type: 'object',
),
example: '{"url": "https://robertsspaceindustries.com/i/cc75a45005a236c6e015dfc2782a2f55ed1e84a2/ADdPNihJzmPbNuTnFsH1DqUeqBRpXdSXVVtgJTyDDgscGKrzJuoFjResiiucPBBDeyrBscqRyZz4qxNsSbWvqUwdG/alien-week-2022-front.webp"}',
)
),
]
),
tags: ['Comm-Links', 'RSI-Website'],
Expand All @@ -110,7 +110,7 @@ public function searchByTitle(Request $request): AnonymousResourceCollection
new OA\Response(
response: 404,
description: 'No Comm-Link found.',
)
),
],
)]
public function reverseImageLinkSearch(Request $request): AnonymousResourceCollection
Expand All @@ -129,7 +129,7 @@ public function reverseImageLinkSearch(Request $request): AnonymousResourceColle
array_pop($parts);
$path = implode('/', $parts);

$image->where('src', 'LIKE', $path . '%');
$image->where('src', 'LIKE', $path.'%');
} else {
$image->where('dir', $dir);
}
Expand Down Expand Up @@ -190,7 +190,7 @@ enum: [
),
),
explode: false,
)
),
],
responses: [
new OA\Response(
Expand All @@ -204,7 +204,7 @@ enum: [
new OA\Response(
response: 404,
description: 'No Comm-Link found.',
)
),
],
)]
public function reverseImageSearch(Request $request): AnonymousResourceCollection
Expand All @@ -230,7 +230,7 @@ public function reverseImageSearch(Request $request): AnonymousResourceCollectio
'pdq_hash4' => $pdqHash[3],
];

$data = $this->getResultImages($hashData, (int)$request->get('similarity'));
$data = $this->getResultImages($hashData, (int) $request->get('similarity'));

return ImageHashResource::collection($data);
}
Expand Down Expand Up @@ -268,7 +268,7 @@ function (object $data) {
$image->similarity_method = __('Basierend auf Merkmalen des Inhalts');
} else {
$image->similarity = round((1 - ($data->pdq_distance / 256)) * 100);
$image->similarity_method = ''; #PDQ
$image->similarity_method = ''; //PDQ
}

$image->pdq_distance = $data->pdq_distance ?? $image->p_distance;
Expand All @@ -284,8 +284,7 @@ function (object $data) {
/**
* Returns the RSI directory hash of an image url
*
* @param string $url The RSI Media URl
*
* @param string $url The RSI Media URl
* @return string The directory hash of the image
*/
private function getDirHashFromImageUrl(string $url): string
Expand All @@ -305,7 +304,7 @@ private function getDirHashFromImageUrl(string $url): string
*/
private function checkExtensionsLoaded(): void
{
if (!extension_loaded('gd') && !extension_loaded('imagick')) {
if (! extension_loaded('gd') && ! extension_loaded('imagick')) {
app('Log')::error('Required extension "GD" or "Imagick" not available.');

throw new HttpException(501, 'Required extension "GD" or "Imagick" not available.');
Expand All @@ -315,7 +314,6 @@ private function checkExtensionsLoaded(): void
/**
* Return hashes based on database connection type
*
* @param array $hashData
*
* @return Builder[]|Collection|\Illuminate\Support\Collection
*/
Expand All @@ -332,8 +330,7 @@ private function getHashesFromDatabase(array $hashData)
/**
* Get the image hashes that equal the provided hash
*
* @param string $hash The image hash
*
* @param string $hash The image hash
* @return Builder[]|Collection
*/
private function getHashesFromSQLiteStore(string $hash)
Expand All @@ -346,17 +343,15 @@ private function getHashesFromSQLiteStore(string $hash)
/**
* Get the image hashes matching the provided hash method and hamming distance
*
* @param array $hashes Image hash split in the middle and hex decoded
*
* @return \Illuminate\Support\Collection
* @param array $hashes Image hash split in the middle and hex decoded
*/
private function getHashesFromSQLStore(array $hashes): \Illuminate\Support\Collection
{
return ImageHashModel::query()
->with('image')
->select('comm_link_image_hashes.comm_link_image_id')
->selectRaw(
<<<SQL
<<<'SQL'
(BIT_COUNT(CONV(HEX(pdq_hash1), 16, 10) ^ CONV(?, 16, 10)) +
BIT_COUNT(CONV(HEX(pdq_hash2), 16, 10) ^ CONV(?, 16, 10)) +
BIT_COUNT(CONV(HEX(pdq_hash3), 16, 10) ^ CONV(?, 16, 10)) +
Expand Down
8 changes: 2 additions & 6 deletions app/Http/Controllers/Api/V2/SC/Char/ArmorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
enum: [
'shops',
'shops.items',
'variants',
]
),
),
Expand All @@ -57,7 +58,6 @@ class ArmorController extends AbstractApiV2Controller
new OA\Parameter(ref: '#/components/parameters/page'),
new OA\Parameter(ref: '#/components/parameters/limit'),
new OA\Parameter(ref: '#/components/parameters/clothing_filter_v2'),
new OA\Parameter(ref: '#/components/parameters/variant_includes_v2'),
new OA\Parameter(name: 'filter[variants]', in: 'query', schema: new OA\Schema(type: 'boolean')),
],
responses: [
Expand Down Expand Up @@ -90,7 +90,6 @@ public function index(Request $request): AnonymousResourceCollection
parameters: [
new OA\Parameter(ref: '#/components/parameters/locale'),
new OA\Parameter(ref: '#/components/parameters/clothing_includes_v2'),
new OA\Parameter(ref: '#/components/parameters/variant_includes_v2'),
new OA\Parameter(
name: 'armor',
in: 'path',
Expand All @@ -105,10 +104,7 @@ public function index(Request $request): AnonymousResourceCollection
new OA\Response(
response: 200,
description: 'An Armor Item',
content: new OA\JsonContent(
type: 'array',
items: new OA\Items(ref: '#/components/schemas/item_v2')
)
content: new OA\JsonContent(ref: '#/components/schemas/item_v2')
),
]
)]
Expand Down
7 changes: 1 addition & 6 deletions app/Http/Controllers/Api/V2/SC/Char/ClothesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class ClothesController extends AbstractApiV2Controller
new OA\Parameter(ref: '#/components/parameters/page'),
new OA\Parameter(ref: '#/components/parameters/limit'),
new OA\Parameter(ref: '#/components/parameters/clothing_filter_v2'),
new OA\Parameter(ref: '#/components/parameters/variant_includes_v2'),
new OA\Parameter(name: 'filter[variants]', in: 'query', schema: new OA\Schema(type: 'boolean')),
],
responses: [
Expand Down Expand Up @@ -63,7 +62,6 @@ public function index(Request $request): AnonymousResourceCollection
parameters: [
new OA\Parameter(ref: '#/components/parameters/locale'),
new OA\Parameter(ref: '#/components/parameters/clothing_includes_v2'),
new OA\Parameter(ref: '#/components/parameters/variant_includes_v2'),
new OA\Parameter(
name: 'clothing',
in: 'path',
Expand All @@ -78,10 +76,7 @@ public function index(Request $request): AnonymousResourceCollection
new OA\Response(
response: 200,
description: 'A Clothing Item',
content: new OA\JsonContent(
type: 'array',
items: new OA\Items(ref: '#/components/schemas/item_v2')
)
content: new OA\JsonContent(ref: '#/components/schemas/item_v2')
),
]
)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ enum: [
new OA\Response(
response: 200,
description: 'A Personal Weapon',
content: new OA\JsonContent(
type: 'array',
items: new OA\Items(ref: '#/components/schemas/personal_weapon_v2')
)
content: new OA\JsonContent(ref: '#/components/schemas/personal_weapon_v2')
),
]
)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class WeaponAttachmentController extends AbstractApiV2Controller
type: 'array',
items: new OA\Items(ref: '#/components/schemas/item_link_v2')
)
)
),
]
)]
public function index(Request $request): AnonymousResourceCollection
Expand Down Expand Up @@ -68,11 +68,8 @@ public function index(Request $request): AnonymousResourceCollection
new OA\Response(
response: 200,
description: 'An Attachment Item',
content: new OA\JsonContent(
type: 'array',
items: new OA\Items(ref: '#/components/schemas/item_v2')
)
)
content: new OA\JsonContent(ref: '#/components/schemas/item_v2')
),
]
)]
public function show(Request $request): AbstractBaseResource
Expand Down
5 changes: 1 addition & 4 deletions app/Http/Controllers/Api/V2/SC/FactionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ public function index(Request $request): AnonymousResourceCollection
new OA\Response(
response: 200,
description: 'A Faction and its relations',
content: new OA\JsonContent(
type: 'array',
items: new OA\Items(ref: '#/components/schemas/faction_v2')
)
content: new OA\JsonContent(ref: '#/components/schemas/faction_v2')
),
]
)]
Expand Down
9 changes: 3 additions & 6 deletions app/Http/Controllers/Api/V2/SC/FoodController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FoodController extends AbstractApiV2Controller
type: 'array',
items: new OA\Items(ref: '#/components/schemas/item_link_v2')
)
)
),
]
)]
public function index(Request $request): AnonymousResourceCollection
Expand Down Expand Up @@ -69,11 +69,8 @@ public function index(Request $request): AnonymousResourceCollection
new OA\Response(
response: 200,
description: 'A Food Item',
content: new OA\JsonContent(
type: 'array',
items: new OA\Items(ref: '#/components/schemas/food_v2')
)
)
content: new OA\JsonContent(ref: '#/components/schemas/food_v2')
),
]
)]
public function show(Request $request): AbstractBaseResource
Expand Down
8 changes: 1 addition & 7 deletions app/Http/Controllers/Api/V2/SC/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class ItemController extends AbstractApiV2Controller
new OA\Parameter(ref: '#/components/parameters/page'),
new OA\Parameter(ref: '#/components/parameters/limit'),
new OA\Parameter(ref: '#/components/parameters/commodity_includes_v2'),
new OA\Parameter(ref: '#/components/parameters/variant_includes_v2'),
new OA\Parameter(name: 'filter[variants]', in: 'query', schema: new OA\Schema(type: 'boolean')),
new OA\Parameter(name: 'filter[type]', in: 'query', schema: new OA\Schema(type: 'string')),
new OA\Parameter(name: 'filter[sub_type]', in: 'query', schema: new OA\Schema(type: 'string')),
Expand Down Expand Up @@ -70,7 +69,6 @@ public function index(Request $request): AnonymousResourceCollection
parameters: [
new OA\Parameter(ref: '#/components/parameters/locale'),
new OA\Parameter(ref: '#/components/parameters/commodity_includes_v2'),
new OA\Parameter(ref: '#/components/parameters/variant_includes_v2'),
new OA\Parameter(
name: 'item',
in: 'path',
Expand All @@ -85,10 +83,7 @@ public function index(Request $request): AnonymousResourceCollection
new OA\Response(
response: 200,
description: 'An Item',
content: new OA\JsonContent(
type: 'array',
items: new OA\Items(ref: '#/components/schemas/item_v2')
)
content: new OA\JsonContent(ref: '#/components/schemas/item_v2')
),
]
)]
Expand Down Expand Up @@ -162,7 +157,6 @@ public function show(Request $request)
new OA\Parameter(ref: '#/components/parameters/limit'),
new OA\Parameter(ref: '#/components/parameters/locale'),
new OA\Parameter(ref: '#/components/parameters/commodity_includes_v2'),
new OA\Parameter(ref: '#/components/parameters/variant_includes_v2'),
new OA\Parameter(name: 'filter[variants]', in: 'query', schema: new OA\Schema(type: 'boolean')),
new OA\Parameter(name: 'filter[type]', in: 'query', schema: new OA\Schema(type: 'string')),
new OA\Parameter(name: 'filter[sub_type]', in: 'query', schema: new OA\Schema(type: 'string')),
Expand Down
Loading

0 comments on commit 374c1d9

Please sign in to comment.