-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConfigurationsController.php
More file actions
107 lines (102 loc) · 3.5 KB
/
ConfigurationsController.php
File metadata and controls
107 lines (102 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php namespace App\Http\Controllers;
/**
* Copyright 2020 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Models\ResourceServer\IApiRepository;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Route;
use models\utils\IEntity;
use ModelSerializers\SerializerRegistry;
use OpenApi\Attributes as OA;
use Symfony\Component\HttpFoundation\Response;
use Exception;
/**
* Class ConfigurationsController
* @package App\Http\Controllers
*/
final class ConfigurationsController extends JsonController
{
/**
* @var IApiRepository
*/
private $repository;
/**
* ConfigurationsController constructor.
* @param IApiRepository $repository
*/
public function __construct(IApiRepository $repository)
{
parent::__construct();
$this->repository = $repository;
}
/**
* @return \Illuminate\Http\JsonResponse|mixed
*/
#[OA\Get(
path: '/.well-known/endpoints',
operationId: 'getEndpointsDefinitions',
description: 'Retrieve all available API endpoints definitions including OAuth2 and public endpoints',
tags: ['Configurations'],
parameters: [
new OA\Parameter(
name: 'expand',
description: 'Expansion parameters',
in: 'query',
required: false,
schema: new OA\Schema(type: 'string')
),
],
responses: [
new OA\Response(
response: Response::HTTP_OK,
description: 'List of all available endpoints',
content: new OA\JsonContent(ref: '#/components/schemas/EndpointsDefinitionsResponse')
),
new OA\Response(
response: Response::HTTP_INTERNAL_SERVER_ERROR,
description: 'Server Error'
),
]
)]
public function getEndpointsDefinitions(){
try {
$items = [];
foreach ($this->repository->getAll() as $i) {
if ($i instanceof IEntity) {
$i = SerializerRegistry::getInstance()->getSerializer($i, SerializerRegistry::SerializerType_Public)->serialize(Request::input('expand', ''));
}
$items[] = $i;
}
$routeCollection = Route::getRoutes();
$public_endpoints = [];
foreach ($routeCollection as $value) {
$uri = $value->uri;
if(!str_contains($uri, 'api/public/v1')) continue;
$public_endpoints[] = [
'route' => $uri,
'http_methods' => $value->methods,
];
}
return $this->ok(
[
'oauth2_endpoints' => $items,
'public_endpoints' => $public_endpoints,
]
);
}
catch (Exception $ex) {
Log::error($ex);
return $this->error500($ex);
}
}
}