Skip to content

Commit

Permalink
Feature/acp 4074/acp 4403 invalid checkout with paypalexpress in glue…
Browse files Browse the repository at this point in the history
… does not produce helpful errors (#19)

* ACP-4403 Added schema merge console
  • Loading branch information
stereomon authored Nov 26, 2024
1 parent 2ef5485 commit 87fa35e
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 50 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ jobs:
fail-fast: false
matrix:
php-version: [
'8.0',
'8.1'
'8.2'
]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -36,7 +35,7 @@ jobs:
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Composer cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
Expand All @@ -59,15 +58,15 @@ jobs:
run: composer cs-check

- name: Codecept tests
if: ${{ matrix.php-version == '8.0' }}
if: ${{ matrix.php-version == '8.2' }}
run: composer test

- name: Codecept tests with coverage
if: ${{ matrix.php-version == '8.1' }}
if: ${{ matrix.php-version == '8.2' }}
run: composer test-cover

- name: Code Coverage Report
if: success() && matrix.php-version == '8.1'
if: success() && matrix.php-version == '8.2'
uses: codecov/codecov-action@v3
with:
file: ./tests/_output/coverage.xml
23 changes: 10 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
"description": "SDK for SyncAPI.",
"license": "proprietary",
"require": {
"php": ">=8.0",
"php": ">=8.2",
"cebe/php-openapi": "^1.6",
"doctrine/inflector": "^1.4.0 || ^2.0",
"spryker-sdk/spryk": "^0.4.0 || ^0.5.0",
"symfony/console": "^4.0.0 || ^5.3 || ^6.0",
"symfony/finder": "^4.0.0 || ^5.3 || ^6.0",
"symfony/process": "^4.0.0 || ^5.4 || ^6"
"symfony/process": "^4.0.0 || ^5.4 || ^6.0"
},
"require-dev": {
"codeception/codeception": "*",
"codeception/stub": "^4.1.0",
"codeception/module-asserts": "*",
"codeception/stub": "^4.1.0",
"mikey179/vfsstream": "^1.6",
"spryker-sdk/architector": "0.1.x-dev",
"phpstan/phpstan": "^2.0",
"rector/rector": "dev-main",
"spryker/code-sniffer": "dev-master",
"symfony/filesystem": "^4.0 || ^5.3",
"symfony/var-dumper": "*",
"phpstan/phpdoc-parser": "~1.5.1"
"symfony/var-dumper": "*"
},
"autoload": {
"psr-4": {
Expand All @@ -46,23 +46,20 @@
}
},
"config": {
"platform": {
"php": "8.0.19"
},
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"sllh/composer-versions-check": true
}
},
"scripts": {
"cs-check": "phpcs --colors -p -s --extensions=php --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml src/SprykerSdk/ tests/",
"cs-fix": "phpcbf --colors -p --extensions=php --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml src/SprykerSdk/ tests/",
"cs-check": "phpcs --colors -p",
"cs-fix": "phpcbf --colors -p",
"stan": "phpstan analyze -l 8 src/SprykerSdk/",
"test": "codecept build && codecept run",
"test-cover": "codecept build && codecept run --coverage-xml",
"rector": "vendor/bin/rector process src/SprykerSdk/ --config architector.php --ansi",
"rector-diff": "vendor/bin/rector process src/SprykerSdk/ --config architector.php --ansi --dry-run",
"rector": "vendor/bin/rector process src/SprykerSdk/ --ansi",
"rector-diff": "vendor/bin/rector process src/SprykerSdk/ --ansi --dry-run",
"local-ci": "composer cs-fix && composer cs-check && composer stan && composer rector-diff && composer test"
}
}
49 changes: 49 additions & 0 deletions phpcs.xml
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>
9 changes: 2 additions & 7 deletions phpstan.neon
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
8 changes: 2 additions & 6 deletions architector.php → rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@
return static function (RectorConfig $rectorConfig) {
$rectorConfig->import(SetList::DEAD_CODE);
$rectorConfig->import(SetList::EARLY_RETURN);
$rectorConfig->import(SetList::PHP_74);
$rectorConfig->import(SetList::PHP_82);

$rectorConfig->parameters()->set(Option::SKIP, [
ChangeAndIfToEarlyReturnRector::class,
ChangeOrIfReturnToEarlyReturnRector::class,
ClosureToArrowFunctionRector::class,
$rectorConfig->skip([
RemoveUselessParamTagRector::class,
RemoveUnusedPromotedPropertyRector::class,
RemoveUselessReturnTagRector::class,
RemoveUselessVarTagRector::class,
ReturnBinaryAndToEarlyReturnRector::class,
]);
};
101 changes: 101 additions & 0 deletions src/SprykerSdk/SyncApi/Console/OpenApiSchemaMergerConsole.php
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class GlueResourceMethodResponseArguments implements ArgumentsInterface
protected ?int $httpResponseCode = null;

/**
* @var array<string>
* @var array<string, array<string, string>>
*/
protected array $extensions = [];

Expand Down Expand Up @@ -159,7 +159,7 @@ public function getModuleName(): ?string
}

/**
* @param array $extensions
* @param array<string, array<string, string>> $extensions
*
* @return void
*/
Expand All @@ -169,7 +169,7 @@ public function setExtensions(array $extensions): void
}

/**
* @return array
* @return array<string, array<string, string>>
*/
public function getExtensions(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class TransferArguments implements ArgumentsInterface
protected array $properties = [];

/**
* @var array<string, string|array>
* @var array<string, string|array<string, string>>
*/
protected array $extensions = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(SyncApiConfig $config)
}

/**
* @param array<array> $commands
* @param array<array<string, string>> $commands
*
* @return void
*/
Expand All @@ -37,7 +37,7 @@ public function runCommands(array $commands): void
/**
* @codeCoverageIgnore
*
* @param array $command
* @param array<string, string> $command
*
* @return void
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
interface CommandRunnerInterface
{
/**
* @param array<array> $commands
* @param array<array<string, string>> $commands
*
* @return void
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class OpenApiHttpMethodInPathValidatorRule implements ValidatorRuleInterface
{
/**
* @var array
* @var array<int, string>
*/
protected const HTTP_METHODS = [
'get',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public function __construct(MessageBuilderInterface $messageBuilder)
/**
* Validates the schema for existence of paths.
*
* @param array $openApi
* @param array<string, string|array<string, string>> $openApi
* @param string $openApiFileName
* @param \Transfer\ValidateResponseTransfer $validateResponseTransfer
* @param array|null $context
* @param array<string, string>|null $context
*
* @return \Transfer\ValidateResponseTransfer
*/
Expand All @@ -47,7 +47,7 @@ public function validate(
}

/**
* @param array $openApi
* @param array<string, string|array<string, string>> $openApi
* @param string $openApiFileName
* @param \Transfer\ValidateResponseTransfer $validateResponseTransfer
*
Expand Down
2 changes: 1 addition & 1 deletion src/SprykerSdk/SyncApi/SyncApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function createOpenApiValidator(): OpenApiValidator
}

/**
* @return array
* @return array<\SprykerSdk\SyncApi\Validator\Rule\ValidatorRuleInterface>
*/
public function getValidatorRules(): array
{
Expand Down
Loading

0 comments on commit 87fa35e

Please sign in to comment.