Skip to content

Commit 6919f6a

Browse files
authored
Merge pull request #141 from RonasIT/feat/update-openapi-version
Update Swagger UI assets
2 parents 90e93d4 + 61abe73 commit 6919f6a

24 files changed

+74
-78
lines changed

resources/assets/swagger/swagger-ui-bundle.js

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/swagger/swagger-ui-bundle.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/swagger/swagger-ui-es-bundle-core.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/swagger/swagger-ui-es-bundle-core.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/swagger/swagger-ui-es-bundle.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/swagger/swagger-ui-es-bundle.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/swagger/swagger-ui-standalone-preset.js

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/swagger/swagger-ui-standalone-preset.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/swagger/swagger-ui.css

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/swagger/swagger-ui.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/swagger/swagger-ui.js

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/swagger/swagger-ui.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Services/SwaggerService.php

+11-14
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,7 @@ protected function saveListResponseDefinitions(array $content, array &$schemaPro
333333

334334
protected function saveObjectResponseDefinitions(array $content, array &$schemaProperties, string $definition): void
335335
{
336-
$definitions = (!empty($this->data['components']['schemas'])) ? $this->data['components']['schemas'] : [];
337-
338-
$properties = Arr::get($definitions, $definition, []);
336+
$properties = Arr::get($this->data, "components.schemas.{$definition}", []);
339337

340338
foreach ($content as $name => $value) {
341339
$property = Arr::get($properties, "properties.{$name}", []);
@@ -533,13 +531,13 @@ protected function savePostRequestParameters($actionName, $rules, array $attribu
533531
{
534532
if ($this->requestHasMoreProperties($actionName)) {
535533
if ($this->requestHasBody()) {
536-
$type = $this->request->header('Content-Type') ?? 'application/json';
534+
$type = $this->request->header('Content-Type', 'application/json');
537535

538536
$this->item['requestBody'] = [
539537
'content' => [
540538
$type => [
541539
'schema' => [
542-
"\$ref" => "#/components/schemas/{$actionName}Object",
540+
'$ref' => "#/components/schemas/{$actionName}Object",
543541
],
544542
],
545543
],
@@ -577,7 +575,7 @@ protected function saveDefinitions($objectName, $rules, $attributes, array $anno
577575
}
578576

579577
$data['example'] = $this->generateExample($data['properties']);
580-
$this->data['components']['schemas'][$objectName . 'Object'] = $data;
578+
$this->data['components']['schemas']["{$objectName}Object"] = $data;
581579
}
582580

583581
protected function getParameterType(array $validation): string
@@ -618,11 +616,8 @@ protected function requestHasMoreProperties($actionName): bool
618616
{
619617
$requestParametersCount = count($this->request->all());
620618

621-
if (isset($this->data['components']['schemas'][$actionName . 'Object']['properties'])) {
622-
$objectParametersCount = count($this->data['components']['schemas'][$actionName . 'Object']['properties']);
623-
} else {
624-
$objectParametersCount = 0;
625-
}
619+
$properties = Arr::get($this->data, "components.schemas.{$actionName}Object.properties", []);
620+
$objectParametersCount = count($properties);
626621

627622
return $requestParametersCount > $objectParametersCount;
628623
}
@@ -1000,9 +995,11 @@ protected function mergeOpenAPIDocs(array &$documentation, array $additionalDocu
1000995
$definitions = array_keys($additionalDocumentation['components']['schemas']);
1001996

1002997
foreach ($definitions as $definition) {
1003-
if (empty($documentation['components']['schemas'][$definition])) {
1004-
$documentation['components']['schemas'][$definition] = $additionalDocumentation['components']['schemas'][$definition];
1005-
}
998+
$documentation = Arr::add(
999+
array: $documentation,
1000+
key: "components.schemas.{$definition}",
1001+
value: $additionalDocumentation['components']['schemas'][$definition],
1002+
);
10061003
}
10071004
}
10081005
}

src/Validators/SwaggerSpecValidator.php

+10-14
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ class SwaggerSpecValidator
7272
'security_definition_type' => ['basic', 'apiKey', 'oauth2'],
7373
];
7474

75+
public const ALLOWED_TYPES = [
76+
self::MIME_TYPE_APPLICATION_URLENCODED,
77+
self::MIME_TYPE_MULTIPART_FORM_DATA,
78+
self::MIME_TYPE_APPLICATION_JSON,
79+
];
80+
7581
public const PATH_PARAM_REGEXP = '#(?<={)[^/}]+(?=})#';
7682
public const PATH_REGEXP = '/^x-/';
7783

@@ -247,23 +253,13 @@ protected function validateRequestBody(array $operation, string $path, string $o
247253

248254
protected function validateRequestBodyContent(array $content, string $operationId): void
249255
{
250-
$allowedContentType = false;
251-
252-
$types = [
253-
self::MIME_TYPE_APPLICATION_URLENCODED,
254-
self::MIME_TYPE_MULTIPART_FORM_DATA,
255-
self::MIME_TYPE_APPLICATION_JSON,
256-
];
256+
$invalidContentTypes = array_diff(array_keys($content), self::ALLOWED_TYPES);
257257

258-
foreach ($types as $type) {
259-
if (!empty($content[$type])) {
260-
$allowedContentType = true;
261-
}
262-
}
258+
if (!empty($invalidContentTypes)) {
259+
$invalidTypes = implode(', ', $invalidContentTypes);
263260

264-
if (!$allowedContentType) {
265261
throw new InvalidSwaggerSpecException(
266-
"Operation '{$operationId}' has body parameters. Only one or the other is allowed."
262+
"Operation '{$operationId}' has invalid content types: {$invalidTypes}."
267263
);
268264
}
269265
}

tests/SwaggerServiceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public static function getConstructorInvalidTmpData(): array
292292
[
293293
'tmpDoc' => 'documentation/invalid_format__request_body__invalid_content',
294294
'exception' => InvalidSwaggerSpecException::class,
295-
'exceptionMessage' => "Validation failed. Operation 'paths./users/{id}.post' has body parameters. Only one or the other is allowed.",
295+
'exceptionMessage' => "Validation failed. Operation 'paths./users/{id}.post' has invalid content types: image/png.",
296296
],
297297
[
298298
'tmpDoc' => 'documentation/invalid_format__response__invalid_items',

tests/fixtures/AutoDocControllerTest/tmp_data.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
"schema": {
2323
"$ref": "#/components/schemas/authloginObject"
2424
}
25-
},
26-
"required": true,
27-
"description": ""
28-
}
25+
}
26+
},
27+
"required": true,
28+
"description": ""
2929
},
3030
"responses": {
3131
"200": {

tests/fixtures/AutoDocControllerTest/tmp_data_with_additional_paths.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
"schema": {
2323
"$ref": "#/components/schemas/authloginObject"
2424
}
25-
},
26-
"required": true,
27-
"description": ""
28-
}
25+
}
26+
},
27+
"required": true,
28+
"description": ""
2929
},
3030
"responses": {
3131
"200": {
@@ -116,10 +116,10 @@
116116
"schema": {
117117
"$ref": "#/components/schemas/authloginObject"
118118
}
119-
},
120-
"required": true,
121-
"description": ""
122-
}
119+
}
120+
},
121+
"required": true,
122+
"description": ""
123123
},
124124
"responses": {
125125
"200": {
@@ -212,10 +212,10 @@
212212
"schema": {
213213
"$ref": "#/components/schemas/apiusersObject"
214214
}
215-
},
216-
"required": true,
217-
"description": ""
218-
}
215+
}
216+
},
217+
"required": true,
218+
"description": ""
219219
},
220220
"responses": {
221221
"403": {

tests/fixtures/LocalDriverTest/tmp_data.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
"schema": {
2525
"$ref": "#/components/schemas/authloginObject"
2626
}
27-
},
28-
"required": true,
29-
"description": ""
30-
}
27+
}
28+
},
29+
"required": true,
30+
"description": ""
3131
},
3232
"responses": {
3333
"200": {
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"openapi":"3.1.0","servers":[{"url":"http:\/\/localhost"}],"paths":{"\/auth\/login":{"post":{"tags":["auth"],"consumes":["application\/json"],"produces":["application\/json"],"parameters":[],"requestBody":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/authloginObject"}},"required":true,"description":""}},"responses":{"200":{"description":"Operation successfully done","content":{"application\/json":{"schema":{"type":"object"},"example":{"token":"some_token","user":{"id":2,"email":"[email protected]","deleted_at":null,"created_at":"2017-11-16 06:08:34","updated_at":"2018-01-01 00:00:00","role_id":2,"state":"confirmed","reset_password_hash":null,"failed_auth_attempts":0,"last_auth_attempt":"2018-01-01 00:00:00","first_name":"user","last_name":null,"set_password_hash_created_at":null,"full_name":"user","new_email":"[email protected]","is_email_verified":true,"role":{"id":2,"name":"client","created_at":null,"updated_at":null,"settable":true}},"ttl":60,"refresh_ttl":20160}}}},"401":{"description":"Unauthorized","content":{"application\/json":{"schema":{"type":"object"},"example":{"error":"You have entered an incorrect credentials."}}}},"400":{"description":"Bad Request","content":{"application\/json":{"schema":{"type":"object"},"example":{"error":"The limit of failed authorization attempts has been reached. You can't login in next 50 minutes."}}}}},"security":[],"description":"","summary":"login"}}},"components":{"schemas":{"authloginObject":{"type":"object","properties":{"email":{"type":"string","description":"2"},"password":{"type":"string","description":""}},"required":["email","password"],"example":{"email":"[email protected]","password":"123"}}}},"info":{"description":"This is automatically collected documentation","version":"0.0.0","title":"Project Title","termsOfService":"","contact":{"email":"[email protected]"}}}
1+
{"openapi":"3.1.0","servers":[{"url":"http:\/\/localhost"}],"paths":{"\/auth\/login":{"post":{"tags":["auth"],"consumes":["application\/json"],"produces":["application\/json"],"parameters":[],"requestBody":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/authloginObject"}}},"required":true,"description":""},"responses":{"200":{"description":"Operation successfully done","content":{"application\/json":{"schema":{"type":"object"},"example":{"token":"some_token","user":{"id":2,"email":"[email protected]","deleted_at":null,"created_at":"2017-11-16 06:08:34","updated_at":"2018-01-01 00:00:00","role_id":2,"state":"confirmed","reset_password_hash":null,"failed_auth_attempts":0,"last_auth_attempt":"2018-01-01 00:00:00","first_name":"user","last_name":null,"set_password_hash_created_at":null,"full_name":"user","new_email":"[email protected]","is_email_verified":true,"role":{"id":2,"name":"client","created_at":null,"updated_at":null,"settable":true}},"ttl":60,"refresh_ttl":20160}}}},"401":{"description":"Unauthorized","content":{"application\/json":{"schema":{"type":"object"},"example":{"error":"You have entered an incorrect credentials."}}}},"400":{"description":"Bad Request","content":{"application\/json":{"schema":{"type":"object"},"example":{"error":"The limit of failed authorization attempts has been reached. You can't login in next 50 minutes."}}}}},"security":[],"description":"","summary":"login"}}},"components":{"schemas":{"authloginObject":{"type":"object","properties":{"email":{"type":"string","description":"2"},"password":{"type":"string","description":""}},"required":["email","password"],"example":{"email":"[email protected]","password":"123"}}}},"info":{"description":"This is automatically collected documentation","version":"0.0.0","title":"Project Title","termsOfService":"","contact":{"email":"[email protected]"}}}

tests/fixtures/RemoteDriverTest/tmp_data.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
"schema": {
2323
"$ref": "#/components/schemas/authloginObject"
2424
}
25-
},
26-
"required": true,
27-
"description": ""
28-
}
25+
}
26+
},
27+
"required": true,
28+
"description": ""
2929
},
3030
"responses": {
3131
"200": {
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"openapi":"3.1.0","host":"localhost","basePath":"\/","schemes":[],"paths":{"\/auth\/login":{"post":{"tags":["auth"],"consumes":["application\/json"],"produces":["application\/json"],"parameters":[],"requestBody":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/authloginObject"}},"required":true,"description":""}},"responses":{"200":{"description":"Operation successfully done","content":{"application\/json":{"schema":{"type":"object"},"example":{"token":"some_token","user":{"id":2,"email":"[email protected]","deleted_at":null,"created_at":"2017-11-16 06:08:34","updated_at":"2018-01-01 00:00:00","role_id":2,"state":"confirmed","reset_password_hash":null,"failed_auth_attempts":0,"last_auth_attempt":"2018-01-01 00:00:00","first_name":"user","last_name":null,"set_password_hash_created_at":null,"full_name":"user","new_email":"[email protected]","is_email_verified":true,"role":{"id":2,"name":"client","created_at":null,"updated_at":null,"settable":true}},"ttl":60,"refresh_ttl":20160}}}},"401":{"description":"Unauthorized","content":{"application\/json":{"schema":{"type":"object"},"example":{"error":"You have entered an incorrect credentials."}}}},"400":{"description":"Bad Request","content":{"application\/json":{"schema":{"type":"object"},"example":{"error":"The limit of failed authorization attempts has been reached. You can't login in next 50 minutes."}}}}},"security":[],"description":"","summary":"login"}}},"components":{"schemas":{"authloginObject":{"type":"object","properties":{"email":{"type":"string","description":"2"},"password":{"type":"string","description":""}},"required":["email","password"],"example":{"email":"[email protected]","password":"123"}}}},"info":{"description":"This is automatically collected documentation","version":"0.0.0","title":"Project Title","termsOfService":"","contact":{"email":"[email protected]"}}}
1+
{"openapi":"3.1.0","host":"localhost","basePath":"\/","schemes":[],"paths":{"\/auth\/login":{"post":{"tags":["auth"],"consumes":["application\/json"],"produces":["application\/json"],"parameters":[],"requestBody":{"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/authloginObject"}}},"required":true,"description":""},"responses":{"200":{"description":"Operation successfully done","content":{"application\/json":{"schema":{"type":"object"},"example":{"token":"some_token","user":{"id":2,"email":"[email protected]","deleted_at":null,"created_at":"2017-11-16 06:08:34","updated_at":"2018-01-01 00:00:00","role_id":2,"state":"confirmed","reset_password_hash":null,"failed_auth_attempts":0,"last_auth_attempt":"2018-01-01 00:00:00","first_name":"user","last_name":null,"set_password_hash_created_at":null,"full_name":"user","new_email":"[email protected]","is_email_verified":true,"role":{"id":2,"name":"client","created_at":null,"updated_at":null,"settable":true}},"ttl":60,"refresh_ttl":20160}}}},"401":{"description":"Unauthorized","content":{"application\/json":{"schema":{"type":"object"},"example":{"error":"You have entered an incorrect credentials."}}}},"400":{"description":"Bad Request","content":{"application\/json":{"schema":{"type":"object"},"example":{"error":"The limit of failed authorization attempts has been reached. You can't login in next 50 minutes."}}}}},"security":[],"description":"","summary":"login"}}},"components":{"schemas":{"authloginObject":{"type":"object","properties":{"email":{"type":"string","description":"2"},"password":{"type":"string","description":""}},"required":["email","password"],"example":{"email":"[email protected]","password":"123"}}}},"info":{"description":"This is automatically collected documentation","version":"0.0.0","title":"Project Title","termsOfService":"","contact":{"email":"[email protected]"}}}

tests/fixtures/StorageDriverTest/tmp_data.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
"schema": {
2323
"$ref": "#/components/schemas/authloginObject"
2424
}
25-
},
26-
"required": true,
27-
"description": ""
28-
}
25+
}
26+
},
27+
"required": true,
28+
"description": ""
2929
},
3030
"responses": {
3131
"200": {

0 commit comments

Comments
 (0)