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 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
26 changes: 24 additions & 2 deletions src/SprykerSdk/SyncApi/Console/OpenApiUpdateConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ class OpenApiUpdateConsole extends AbstractConsole
*/
public const ARGUMENT_OPENAPI_DOC_DESCRIPTION = 'A JSON-ed string that contains a valid OpenAPI scheme';

/**
* @var string
*/
public const OPTION_OPEN_API_DOC_FILE = 'openapi-doc-file';

/**
* @var string
*/
public const OPTION_OPEN_API_DOC_FILE_SHORT = 'd';

/**
* @var string
*/
public const OPTION_OPEN_API_DOC_FILE_DESCRIPTION = 'Path to source OpenAPI file. Use this option if you want a provide a source file instead of source JSON. Supports both JSON and YAML files.';

/**
* @var string
*/
Expand Down Expand Up @@ -64,7 +79,7 @@ protected function configure(): void
->setDescription('Updates an OpenAPI file specified in options with provided OpenAPI doc')
->addArgument(
static::ARGUMENT_OPENAPI_DOC,
InputArgument::REQUIRED,
InputArgument::OPTIONAL,
static::ARGUMENT_OPENAPI_DOC_DESCRIPTION,
)
->addOption(
Expand All @@ -74,12 +89,18 @@ protected function configure(): void
static::OPTION_OPEN_API_FILE_DESCRIPTION,
$this->getConfig()->getDefaultRelativePathToOpenApiFile(),
)
->addOption(
static::OPTION_OPEN_API_DOC_FILE,
static::OPTION_OPEN_API_DOC_FILE_SHORT,
InputOption::VALUE_OPTIONAL,
static::OPTION_OPEN_API_DOC_FILE_DESCRIPTION,
)
->addOption(
static::OPTION_PROJECT_ROOT,
static::OPTION_PROJECT_ROOT_SHORT,
InputOption::VALUE_OPTIONAL,
static::OPTION_PROJECT_ROOT_DESCRIPTION,
$this->getConfig()->getProjectRootPath(),
'',
);
}

Expand All @@ -93,6 +114,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
{
$updateOpenApiRequestTransfer = (new UpdateOpenApiRequestTransfer())
->setOpenApiDoc($input->getArgument(static::ARGUMENT_OPENAPI_DOC))
->setOpenApiDocFile($input->getOption(static::OPTION_OPEN_API_DOC_FILE))
->setOpenApiFile($input->getOption(static::OPTION_OPEN_API_FILE))
->setProjectRoot($input->getOption(static::OPTION_PROJECT_ROOT));

Expand Down
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;
}
}

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 $targetOpenApi;
}
}
Loading