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

[APPS-4380] Components upgrade #15

Open
wants to merge 14 commits into
base: feature/apps-4380-add-default-endpoints
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
34 changes: 34 additions & 0 deletions src/SprykerSdk/SyncApi/OpenApi/Merger/ComponentMerger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* Copyright © 2019-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace SprykerSdk\SyncApi\OpenApi\Merger;

use cebe\openapi\spec\OpenApi;

class ComponentMerger implements MergerInterface
{
use OpenApiAccessorTrait;

/**
* @param \cebe\openapi\spec\OpenApi $targetOpenApi
* @param \cebe\openapi\spec\OpenApi $sourceOpenApi
*
* @return \cebe\openapi\spec\OpenApi
*/
public function merge(OpenApi $targetOpenApi, OpenApi $sourceOpenApi): OpenApi
{
foreach ($this->getParameters($sourceOpenApi) as $parameterName => $parameter) {
$this->addParameter($targetOpenApi, $parameterName, $parameter);
}

foreach ($this->getSchemas($sourceOpenApi) as $schemaName => $schema) {
$this->addSchema($targetOpenApi, $schemaName, $schema);
}

return $targetOpenApi;
}
}
4 changes: 1 addition & 3 deletions src/SprykerSdk/SyncApi/OpenApi/Merger/ComponentsCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public function cleanUnused(OpenApi $openApi): OpenApi

$references = ReferenceFinder::findInArray($openApiAsArray);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does anyone know why the OpenAPI schema is converted to JSON here as part of removing unused elements? There should definitely be a comment describing why that is necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed usage of this class but did not delete it for now - we may need to discuss this with Maksym when he's back from his vacation to understand if there is anything preventing us from deleting it.


$openApi = $this->cleanUnusedParameters($openApi, $references);

return $this->cleanUnusedSchemas($openApi, $references);
return $this->cleanUnusedParameters($openApi, $references);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't remember seeing cleanup as part of the specification. What was the argument for implementing this, rather than treating unused parameters as a bug in the component sending the OpenAPI schema update?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed usage

}

/**
Expand Down

This file was deleted.

This file was deleted.

50 changes: 50 additions & 0 deletions src/SprykerSdk/SyncApi/OpenApi/Merger/OpenApiMerger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* Copyright © 2019-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace SprykerSdk\SyncApi\OpenApi\Merger;

use cebe\openapi\spec\OpenApi;

class OpenApiMerger implements MergerInterface
{
/**
* @var array<\SprykerSdk\SyncApi\OpenApi\Merger\MergerInterface>
*/
protected array $mergerCollection;

/**
* @var \SprykerSdk\SyncApi\OpenApi\Merger\ComponentsCleanerInterface
*/
protected ComponentsCleanerInterface $componentsCleaner;

/**
* @param array<\SprykerSdk\SyncApi\OpenApi\Merger\MergerInterface> $mergerCollection
* @param \SprykerSdk\SyncApi\OpenApi\Merger\ComponentsCleanerInterface $componentsCleaner
*/
public function __construct(
array $mergerCollection,
ComponentsCleanerInterface $componentsCleaner
) {
$this->mergerCollection = $mergerCollection;
$this->componentsCleaner = $componentsCleaner;
}

/**
* @param \cebe\openapi\spec\OpenApi $targetOpenApi
* @param \cebe\openapi\spec\OpenApi $sourceOpenApi
*
* @return \cebe\openapi\spec\OpenApi
*/
public function merge(OpenApi $targetOpenApi, OpenApi $sourceOpenApi): OpenApi
{
foreach ($this->mergerCollection as $merger) {
$targetOpenApi = $merger->merge($targetOpenApi, $sourceOpenApi);
}

return $this->componentsCleaner->cleanUnused($targetOpenApi);
}
}
Loading