forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefaultController.php
More file actions
98 lines (81 loc) · 2.56 KB
/
DefaultController.php
File metadata and controls
98 lines (81 loc) · 2.56 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
<?php declare(strict_types=1);
/**
* Issue 21334 - Abstract PHP Variable Naming Convention
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
* PHP version 8.1
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator
* https://openapi-generator.tech
* Do not edit the class manually.
*
* Source files are located at:
*
* > https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/php-laravel/
*/
namespace OpenAPI\Server\Http\Controllers;
use Crell\Serde\SerdeCommon;
use Illuminate\Routing\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use OpenAPI\Server\Api\DefaultApiInterface;
class DefaultController extends Controller
{
/**
* Constructor
*/
public function __construct(
private readonly DefaultApiInterface $api,
private readonly SerdeCommon $serde = new SerdeCommon(),
)
{
}
/**
* Operation getDummy
*
* .
*
*/
public function getDummy(Request $request): JsonResponse
{
$validator = Validator::make(
array_merge(
[
],
$request->all(),
),
[
'paramCamelCase' => [
'string',
],
'ParamPascalCase' => [
'string',
],
'param_withRandomCase' => [
'string',
],
],
);
if ($validator->fails()) {
return response()->json(['error' => 'Invalid input'], 400);
}
$paramCamelCase = $request->string('paramCamelCase')->value();
$ParamPascalCase = $request->string('ParamPascalCase')->value();
$param_withRandomCase = $request->string('param_withRandomCase')->value();
try {
$apiResult = $this->api->getDummy($paramCamelCase, $ParamPascalCase, $param_withRandomCase);
} catch (\Exception $exception) {
// This shouldn't happen
report($exception);
return response()->json(['error' => $exception->getMessage()], 500);
}
if ($apiResult instanceof \OpenAPI\Server\Model\NoContent200) {
return response()->json($this->serde->serialize($apiResult, format: 'array'), 200);
}
// This shouldn't happen
return response()->abort(500);
}
}