-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/acp 4074/acp 4403 invalid checkout with paypalexpress in glue…
… does not produce helpful errors (#19) * ACP-4403 Added schema merge console
- Loading branch information
Showing
15 changed files
with
187 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="Spryker App Store Suite"> | ||
<description> | ||
Spryker Coding Standard for the App Store Suite. | ||
|
||
Extends the main Spryker Coding Standard. | ||
All sniffs in ./Sniffs will be auto loaded | ||
</description> | ||
|
||
<config name="php_version" value="82000"/> | ||
|
||
<file>src/SprykerSdk</file> | ||
<file>tests/</file> | ||
|
||
<exclude-pattern>*/src/Generated/*</exclude-pattern> | ||
<exclude-pattern>*/src/Orm/*/Base/</exclude-pattern> | ||
<exclude-pattern>*/src/Orm/*/Map/</exclude-pattern> | ||
<exclude-pattern>*/src/Orm/Propel/</exclude-pattern> | ||
<exclude-pattern>*/tests/_support/_generated/*</exclude-pattern> | ||
<exclude-pattern>*/tests/_helpers/*</exclude-pattern> | ||
<exclude-pattern>*/tests/_output/*</exclude-pattern> | ||
<exclude-pattern>./docker/*</exclude-pattern> | ||
<exclude-pattern>./data/cache/*</exclude-pattern> | ||
<exclude-pattern>./data/GLOBAL/cache/*</exclude-pattern> | ||
<exclude-pattern>*/node_modules/*</exclude-pattern> | ||
|
||
<rule ref="vendor/spryker/code-sniffer/Spryker/ruleset.xml"> | ||
<exclude name="Spryker.Commenting.DocBlock"/> | ||
<exclude name="Spryker.Commenting.DocBlockParam"/> | ||
<exclude name="Spryker.Commenting.DocBlockReturnVoid"/> | ||
<exclude name="Spryker.Commenting.DocBlockParamAllowDefaultValue"/> | ||
<exclude name="Spryker.Commenting.DisallowArrayTypeHintSyntax"/> | ||
</rule> | ||
|
||
<rule ref="vendor/spryker/code-sniffer/SprykerStrict/ruleset.xml"> | ||
<exclude name="SprykerStrict.TypeHints.ReturnTypeHint"/> | ||
<exclude name="SprykerStrict.TypeHints.ParameterTypeHint"/> | ||
<exclude name="SprykerStrict.TypeHints.PropertyTypeHint"/> | ||
</rule> | ||
|
||
<!-- Define your own sniffs here --> | ||
|
||
<rule ref="Spryker.Internal.SprykerDisallowFunctions"> | ||
<properties> | ||
<property name="phpVersion" value="8.2"/> | ||
</properties> | ||
</rule> | ||
|
||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
parameters: | ||
level: 8 | ||
checkMissingIterableValueType: false | ||
|
||
bootstrapFiles: | ||
- phpstan-bootstrap.php | ||
|
||
ignoreErrors: | ||
- '#Binary operation "\." between array<string>\|bool\|string\|null and .+ results in an error.#' | ||
- '#Parameter .+ of method .+Transfer::.+\(\).+ given.#' | ||
|
||
reportUnmatchedIgnoredErrors: false | ||
- | ||
identifier: missingType.iterableValue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/SprykerSdk/SyncApi/Console/OpenApiSchemaMergerConsole.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?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\Console; | ||
|
||
use cebe\openapi\spec\OpenApi; | ||
use cebe\openapi\Writer; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Yaml\Yaml; | ||
|
||
class OpenApiSchemaMergerConsole extends AbstractConsole | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public const COMMAND_NAME = 'openapi:schema:merge'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public const DESCRIPTION = 'This command merges OpenApi Specs from several sources and a root definition into one.'; | ||
|
||
protected function configure(): void | ||
{ | ||
$this->setName(static::COMMAND_NAME); | ||
$this->setDescription(static::DESCRIPTION); | ||
|
||
$this->addArgument('source', InputArgument::REQUIRED, 'The root file of the OpenApi schema which will be used to merge with other schemas.'); | ||
$this->addArgument('target', InputArgument::REQUIRED, 'The target file name that should be created after merge.'); | ||
|
||
$this->addOption('additional-schemas', 'a', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'The additional OpenApi schema files that should be merged with the root schema.'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$source = sprintf('%s/%s', getcwd(), $input->getArgument('source')); | ||
$target = sprintf('%s/%s', getcwd(), $input->getArgument('target')); | ||
|
||
$additionalSchemas = $input->getOption('additional-schemas'); | ||
|
||
$yaml = new Yaml(); | ||
$sourceSchema = $yaml->parseFile($source); | ||
|
||
$paths = $sourceSchema['paths'] ?? []; | ||
$schemas = $sourceSchema['components']['schemas'] ?? []; | ||
$parameters = $sourceSchema['components']['parameters'] ?? []; | ||
|
||
foreach ($additionalSchemas as $additionalSchema) { | ||
$additionalSchema = sprintf('%s/%s', getcwd(), $additionalSchema); | ||
$coreSchema = $yaml->parseFile($additionalSchema); | ||
$paths = $this->recursiveMerge($coreSchema['paths'] ?? [], $paths); | ||
$schemas = $this->recursiveMerge($coreSchema['components']['schemas'] ?? [], $schemas); | ||
$parameters = $this->recursiveMerge($coreSchema['components']['parameters'] ?? [], $parameters); | ||
} | ||
|
||
$mergedOpenApi = new OpenApi([ | ||
'openapi' => $sourceSchema['openapi'], | ||
'info' => $sourceSchema['info'], | ||
'servers' => $sourceSchema['servers'], | ||
'paths' => $paths, | ||
'components' => [ | ||
'schemas' => $schemas, | ||
'parameters' => $parameters, | ||
], | ||
'security' => $sourceSchema['security'] ?? [], | ||
'tags' => $sourceSchema['tags'] ?? [], | ||
'externalDocs' => $sourceSchema['externalDocs'] ?? [], | ||
]); | ||
|
||
// Save the merged specification to a file | ||
Writer::writeToYamlFile($mergedOpenApi, $target); | ||
|
||
return static::CODE_SUCCESS; | ||
} | ||
|
||
/** | ||
* @param array $array1 | ||
* @param array $array2 | ||
* | ||
* @return array | ||
*/ | ||
protected function recursiveMerge(array $array1, array $array2): array | ||
{ | ||
foreach ($array2 as $key => $value) { | ||
if (is_array($value) && isset($array1[$key]) && is_array($array1[$key])) { | ||
$array1[$key] = $this->recursiveMerge($array1[$key], $value); | ||
} else { | ||
$array1[$key] = $value; | ||
} | ||
} | ||
|
||
return $array1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.