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

[feat]: update openapi version #134

Merged
merged 8 commits into from
Oct 7, 2024
Merged

Conversation

aizlee
Copy link
Contributor

@aizlee aizlee commented Sep 18, 2024

Description

Update OpenAPI version to 3.1.0

src/Services/SwaggerService.php Outdated Show resolved Hide resolved
Comment on lines +336 to +338
$definitions = (!empty($this->data['components']['schemas'])) ? $this->data['components']['schemas'] : [];

$properties = Arr::get($definitions, $definition, []);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

$this->item['parameters'][] = [
'in' => 'body',
'name' => 'body',
$type = $this->request->header('Content-Type') ?? 'application/json';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$type = $this->request->header('Content-Type') ?? 'application/json';
$type = $this->request->header('Content-Type', 'application/json');

'content' => [
$type => [
'schema' => [
"\$ref" => "#/components/schemas/{$actionName}Object",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"\$ref" => "#/components/schemas/{$actionName}Object",
'$ref' => "#/components/schemas/{$actionName}Object",

@@ -559,7 +577,7 @@ protected function saveDefinitions($objectName, $rules, $attributes, array $anno
}

$data['example'] = $this->generateExample($data['properties']);
$this->data['definitions'][$objectName . 'Object'] = $data;
$this->data['components']['schemas'][$objectName . 'Object'] = $data;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->data['components']['schemas'][$objectName . 'Object'] = $data;
$this->data['components']['schemas']["{$objectName}Object"] = $data;

Comment on lines +621 to 625
if (isset($this->data['components']['schemas'][$actionName . 'Object']['properties'])) {
$objectParametersCount = count($this->data['components']['schemas'][$actionName . 'Object']['properties']);
} else {
$objectParametersCount = 0;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);

Comment on lines +1003 to +1004
if (empty($documentation['components']['schemas'][$definition])) {
$documentation['components']['schemas'][$definition] = $additionalDocumentation['components']['schemas'][$definition];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (empty($documentation['components']['schemas'][$definition])) {
$documentation['components']['schemas'][$definition] = $additionalDocumentation['components']['schemas'][$definition];
Arr::add($documentation, "components.schemas.{$definition}, $additionalDocumentation['components']['schemas'][$definition]);

{
$allowedContentType = false;

$types = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move it to the class const


if (!$allowedContentType) {
throw new InvalidSwaggerSpecException(
"Operation '{$operationId}' has body parameters. Only one or the other is allowed."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Operation '{$operationId}' has body parameters. Only one or the other is allowed."
"Operation '{$operationId}' has invalid content types: {$actualTypes}."

Copy link

sonarqubecloud bot commented Oct 7, 2024

@DenTray
Copy link
Collaborator

DenTray commented Oct 7, 2024

@aizlee please make refactoring accordingly my comments as a separate PR

@DenTray DenTray merged commit 3f85697 into master Oct 7, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants