Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Swagger UI assets #141

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions resources/assets/swagger/swagger-ui-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/assets/swagger/swagger-ui-bundle.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions resources/assets/swagger/swagger-ui-es-bundle-core.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions resources/assets/swagger/swagger-ui-es-bundle-core.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions resources/assets/swagger/swagger-ui-es-bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions resources/assets/swagger/swagger-ui-es-bundle.js.map

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions resources/assets/swagger/swagger-ui-standalone-preset.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions resources/assets/swagger/swagger-ui.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/assets/swagger/swagger-ui.css.map

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions resources/assets/swagger/swagger-ui.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/assets/swagger/swagger-ui.js.map

Large diffs are not rendered by default.

25 changes: 11 additions & 14 deletions src/Services/SwaggerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,7 @@ protected function saveListResponseDefinitions(array $content, array &$schemaPro

protected function saveObjectResponseDefinitions(array $content, array &$schemaProperties, string $definition): void
{
$definitions = (!empty($this->data['components']['schemas'])) ? $this->data['components']['schemas'] : [];

$properties = Arr::get($definitions, $definition, []);
$properties = Arr::get($this->data, "components.schemas.{$definition}", []);

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

$this->item['requestBody'] = [
'content' => [
$type => [
'schema' => [
"\$ref" => "#/components/schemas/{$actionName}Object",
'$ref' => "#/components/schemas/{$actionName}Object",
],
],
],
Expand Down Expand Up @@ -577,7 +575,7 @@ protected function saveDefinitions($objectName, $rules, $attributes, array $anno
}

$data['example'] = $this->generateExample($data['properties']);
$this->data['components']['schemas'][$objectName . 'Object'] = $data;
$this->data['components']['schemas']["{$objectName}Object"] = $data;
}

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

if (isset($this->data['components']['schemas'][$actionName . 'Object']['properties'])) {
$objectParametersCount = count($this->data['components']['schemas'][$actionName . 'Object']['properties']);
} else {
$objectParametersCount = 0;
}
$properties = Arr::get($this->data, "components.schemas.{$actionName}Object.properties", []);
$objectParametersCount = count($properties);

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

foreach ($definitions as $definition) {
if (empty($documentation['components']['schemas'][$definition])) {
$documentation['components']['schemas'][$definition] = $additionalDocumentation['components']['schemas'][$definition];
}
$documentation = Arr::add(
array: $documentation,
key: "components.schemas.{$definition}",
value: $additionalDocumentation['components']['schemas'][$definition],
);
}
}
}
24 changes: 10 additions & 14 deletions src/Validators/SwaggerSpecValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ class SwaggerSpecValidator
'security_definition_type' => ['basic', 'apiKey', 'oauth2'],
];

public const ALLOWED_TYPES = [
self::MIME_TYPE_APPLICATION_URLENCODED,
self::MIME_TYPE_MULTIPART_FORM_DATA,
self::MIME_TYPE_APPLICATION_JSON,
];

public const PATH_PARAM_REGEXP = '#(?<={)[^/}]+(?=})#';
public const PATH_REGEXP = '/^x-/';

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

protected function validateRequestBodyContent(array $content, string $operationId): void
{
$allowedContentType = false;

$types = [
self::MIME_TYPE_APPLICATION_URLENCODED,
self::MIME_TYPE_MULTIPART_FORM_DATA,
self::MIME_TYPE_APPLICATION_JSON,
];
$invalidContentTypes = array_diff(array_keys($content), self::ALLOWED_TYPES);

foreach ($types as $type) {
if (!empty($content[$type])) {
$allowedContentType = true;
}
}
if (!empty($invalidContentTypes)) {
$invalidTypes = implode(', ', $invalidContentTypes);

if (!$allowedContentType) {
throw new InvalidSwaggerSpecException(
"Operation '{$operationId}' has body parameters. Only one or the other is allowed."
"Operation '{$operationId}' has invalid content types: {$invalidTypes}."
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/SwaggerServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public static function getConstructorInvalidTmpData(): array
[
'tmpDoc' => 'documentation/invalid_format__request_body__invalid_content',
'exception' => InvalidSwaggerSpecException::class,
'exceptionMessage' => "Validation failed. Operation 'paths./users/{id}.post' has body parameters. Only one or the other is allowed.",
'exceptionMessage' => "Validation failed. Operation 'paths./users/{id}.post' has invalid content types: image/png.",
],
[
'tmpDoc' => 'documentation/invalid_format__response__invalid_items',
Expand Down
8 changes: 4 additions & 4 deletions tests/fixtures/AutoDocControllerTest/tmp_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"schema": {
"$ref": "#/components/schemas/authloginObject"
}
},
"required": true,
"description": ""
}
}
},
"required": true,
"description": ""
},
"responses": {
"200": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"schema": {
"$ref": "#/components/schemas/authloginObject"
}
},
"required": true,
"description": ""
}
}
},
"required": true,
"description": ""
},
"responses": {
"200": {
Expand Down Expand Up @@ -116,10 +116,10 @@
"schema": {
"$ref": "#/components/schemas/authloginObject"
}
},
"required": true,
"description": ""
}
}
},
"required": true,
"description": ""
},
"responses": {
"200": {
Expand Down Expand Up @@ -212,10 +212,10 @@
"schema": {
"$ref": "#/components/schemas/apiusersObject"
}
},
"required": true,
"description": ""
}
}
},
"required": true,
"description": ""
},
"responses": {
"403": {
Expand Down
8 changes: 4 additions & 4 deletions tests/fixtures/LocalDriverTest/tmp_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"schema": {
"$ref": "#/components/schemas/authloginObject"
}
},
"required": true,
"description": ""
}
}
},
"required": true,
"description": ""
},
"responses": {
"200": {
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/LocalDriverTest/tmp_data_non_formatted.json
Original file line number Diff line number Diff line change
@@ -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]"}}}
{"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]"}}}
8 changes: 4 additions & 4 deletions tests/fixtures/RemoteDriverTest/tmp_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"schema": {
"$ref": "#/components/schemas/authloginObject"
}
},
"required": true,
"description": ""
}
}
},
"required": true,
"description": ""
},
"responses": {
"200": {
Expand Down
Original file line number Diff line number Diff line change
@@ -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]"}}}
{"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]"}}}
8 changes: 4 additions & 4 deletions tests/fixtures/StorageDriverTest/tmp_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"schema": {
"$ref": "#/components/schemas/authloginObject"
}
},
"required": true,
"description": ""
}
}
},
"required": true,
"description": ""
},
"responses": {
"200": {
Expand Down
Loading
Loading