-
Notifications
You must be signed in to change notification settings - Fork 0
/
openapi-validator.php
261 lines (231 loc) · 9.02 KB
/
openapi-validator.php
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<?php
use KentarouTakeda\Laravel\OpenApiValidator\SchemaRepository\L5SwaggerResolver;
use KentarouTakeda\Laravel\OpenApiValidator\SchemaRepository\LaravelOpenApiResolver;
use Symfony\Component\HttpFoundation\Response;
return [
/*
|--------------------------------------------------------------------------
| Default OpenAPI Schema Provider
|--------------------------------------------------------------------------
|
| This setting determines the default OpenAPI schema provider to be used.
| The default provider is `laravel-openapi` and can be customized through
| the 'OPENAPI_VALIDATOR_PROVIDER' environment variable.
|
*/
'default' => (string) env(
'OPENAPI_VALIDATOR_PROVIDER',
'laravel-openapi'
),
/*
|--------------------------------------------------------------------------
| Validate Error Responses Generated by Controllers and Subsequent Processes
|--------------------------------------------------------------------------
|
| This setting determines whether to validate error responses generated by
| controllers and subsequent processes against the OpenAPI schema.
| It ensures that error responses conform to the defined API specifications,
| including status codes, headers, and body structures.
|
*/
'validate_error_responses' => (bool) env(
'OPENAPI_VALIDATOR_VALIDATE_ERROR_RESPONSES',
true
),
/*
|--------------------------------------------------------------------------
| Respond with Error on Response Validation Failure
|--------------------------------------------------------------------------
|
| This setting determines whether the OpenAPI validator should respond with
| an error when it fails to validate a response.
|
*/
'respond_error_on_res_validation_failure' => (bool) env(
'OPENAPI_VALIDATOR_RESPOND_WITH_ERROR_ON_RESPONSE_VALIDATION_FAILURE',
env('APP_DEBUG', false),
),
/*
|--------------------------------------------------------------------------
| Error on No Path
|--------------------------------------------------------------------------
|
| This setting determines whether to respond with an error when the path
| corresponding to the request is not defined in the OpenAPI schema.
| The default behavior is according to `APP_DEBUG` and can be customized
| through the 'OPENAPI_VALIDATOR_ERROR_ON_NO_PATH' environment variable.
|
*/
'error_on_no_path' => (bool) env(
'OPENAPI_VALIDATOR_ERROR_ON_NO_PATH',
env('APP_DEBUG', false),
),
/*
|--------------------------------------------------------------------------
| Include Response Validation Error Detail in Response
|--------------------------------------------------------------------------
|
| This setting determines whether the OpenAPI validator should include
| details of response validation errors in the response. The default value
| is `true` and can be customized through the
| 'OPENAPI_VALIDATOR_INCLUDE_RES_ERROR_IN_RESPONSE' environment variable.
|
*/
'include_req_error_detail_in_response' => (bool) env(
'OPENAPI_VALIDATOR_INCLUDE_REQ_ERROR_IN_RESPONSE',
true
),
/*
|--------------------------------------------------------------------------
| Include Request Validation Error Detail in Response
|--------------------------------------------------------------------------
|
| This setting determines whether the OpenAPI validator should include
| details of response validation errors in the response. The default
| behavior is according to `APP`DEBUG` and can be customized through the
| 'OPENAPI_VALIDATOR_INCLUDE_RES_ERROR_IN_RESPONSE' environment variable.
|
*/
'include_res_error_detail_in_response' => (bool) env(
'OPENAPI_VALIDATOR_INCLUDE_RES_ERROR_IN_RESPONSE',
env('APP_DEBUG', false),
),
/*
|--------------------------------------------------------------------------
| Include Trace Information in Response
|--------------------------------------------------------------------------
|
| This setting determines whether the OpenAPI validator should include
| trace information in the error response. The default behavior is
| according to `APP`DEBUG` and can be customized through the
| 'OPENAPI_VALIDATOR_INCLUDE_TRACE_IN_RESPONSE' environment variable.
|
*/
'include_trace_in_response' => (bool) env(
'OPENAPI_VALIDATOR_INCLUDE_TRACE_IN_RESPONSE',
env('APP_DEBUG', false),
),
/*
|--------------------------------------------------------------------------
| Include Original Response in Error Response
|--------------------------------------------------------------------------
|
| This setting determines whether the OpenAPI validator should include
| the original response in the error response. The default behavior is
| according to `APP_DEBUG` and can be customized through the
| 'OPENAPI_VALIDATOR_INCLUDE_ORIGINAL_RES_IN_RESPONSE' environment variable.
|
*/
'include_original_res_in_response' => (bool) env(
'OPENAPI_VALIDATOR_INCLUDE_ORIGINAL_RES_IN_RESPONSE',
env('APP_DEBUG', false),
),
/*
|--------------------------------------------------------------------------
| Request Error Log Level
|--------------------------------------------------------------------------
|
| This setting determines the log level for request errors in the OpenAPI
| validator. The default level is 'info'. This can be customized through
| the 'OPENAPI_VALIDATOR_REQUEST_ERROR_LOG_LEVEL' environment variable.
|
| If set to null, no logging will occur.
|
| Log levels:
| emergency, alert, critical, error, warning, notice, info, debug
|
*/
'req_error_log_level' => (string) env(
'OPENAPI_VALIDATOR_REQUEST_ERROR_LOG_LEVEL',
'info'
),
/*
|--------------------------------------------------------------------------
| Response Error Log Level
|--------------------------------------------------------------------------
|
| This setting determines the log level for response errors in the OpenAPI
| validator. The default level is 'warning'. This can be customized through
| the 'OPENAPI_VALIDATOR_RESPONSE_ERROR_LOG_LEVEL' environment variable.
|
| If set to null, no logging will occur.
|
| Log levels:
| emergency, alert, critical, error, warning, notice, info, debug
|
*/
'res_error_log_level' => (string) env(
'OPENAPI_VALIDATOR_RESPONSE_ERROR_LOG_LEVEL',
'warning'
),
/*
|--------------------------------------------------------------------------
| OpenAPI Schema providers.
|--------------------------------------------------------------------------
|
| By default, `laravel-openapi` is used. If your system handles multiple
| OpenAPI specifications, you can specify which one to use with the
| middleware parameter `provider`.
|
| See the sample below for supported resolvers and settings.
|
*/
'providers' => [
/*
| Laravel OpenAPI
|
| https://github.com/vyuldashev/laravel-openapi
*/
'laravel-openapi' => [
'resolver' => LaravelOpenApiResolver::class,
'collection' => (string) env(
'OPENAPI_VALIDATOR_COLLECTION_NAME',
'default'
),
],
/*
| L5-Swagger
|
| https://github.com/DarkaOnLine/L5-Swagger
*/
'l5-swagger' => [
'resolver' => L5SwaggerResolver::class,
'documentation' => (string) env(
'OPENAPI_VALIDATOR_COLLECTION_NAME',
'default'
),
],
],
/*
|--------------------------------------------------------------------------
| Enable Swagger UI
|--------------------------------------------------------------------------
|
| This setting controls whether the Swagger UI is enabled or not. It can be
| set via the 'OPENAPI_VALIDATOR_IS_SWAGGER_UI_ENABLED' environment variable.
| The default behavior is according to `APP`DEBUG`
|
*/
'is_swagger_ui_enabled' => (bool) env(
'OPENAPI_VALIDATOR_IS_SWAGGER_UI_ENABLED',
env('APP_DEBUG', false),
),
/*
|--------------------------------------------------------------------------
| Internal Settings
|--------------------------------------------------------------------------
|
| These are internal settings for the OpenAPI validator. You can change
| these if necessary.
|
*/
'cache_directory' => storage_path('openapi-validator'),
'non_validated_response_codes' => [
Response::HTTP_MOVED_PERMANENTLY,
Response::HTTP_FOUND,
Response::HTTP_SEE_OTHER,
Response::HTTP_NOT_MODIFIED,
Response::HTTP_TEMPORARY_REDIRECT,
Response::HTTP_PERMANENTLY_REDIRECT,
],
];