Skip to content

Commit 860b5a0

Browse files
authored
Merge pull request #57 from DoclerLabs/fix-dependabot-alert-about-vulnerability-with-composer-version
Fix dependabot alert about vulnerability with composer version
2 parents 1c6de73 + 2bbb790 commit 860b5a0

14 files changed

+228
-44
lines changed

.php_cs.php

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'@PSR2' => true,
1313
'array_syntax' => ['syntax' => 'short'],
1414
'no_multiline_whitespace_before_semicolons' => true,
15+
'no_blank_lines_after_class_opening' => true,
1516
'no_short_echo_tag' => true,
1617
'no_unused_imports' => true,
1718
'blank_line_after_opening_tag' => true,

CHANGELOG.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [7.2.2] - 2021-10-15
8+
### Fixed
9+
- ext- in generated clients composer.json is added according to what is actually being used
10+
11+
## [7.2.1] - 2021-10-07
12+
### Fixed
13+
- Changed default php-cs-fixer configuration to remove blank lines after class opening, according to PSR12 (`no_blank_lines_after_class_opening`)
14+
715
## [7.2.0] - 2021-09-24
816
### Removed
917
- Remove virtual package dependency (psr/http-client-implementation)
1018

1119
## [7.1.1] - 2021-09-09
1220
### Fixed
13-
- Changed default php-cs-fixer configuration to add blank line after opening tag, according to PSR12
21+
- Changed default php-cs-fixer configuration to add blank line after opening tag, according to PSR12 (`blank_line_after_opening_tag`)
1422

1523
## [7.1.0] - 2021-08-30
1624
### Added

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"twig/twig": "^3.0"
3535
},
3636
"require-dev": {
37-
"composer/composer": "^2.0",
37+
"composer/composer": "^2.1",
3838
"php-coveralls/php-coveralls": "^2.2",
3939
"phpstan/phpstan": "^0.12.32",
4040
"phpunit/phpunit": "^9.2",

composer.lock

+37-36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/gen/composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"require": {
1212
"php": ">=7.4",
1313
"docler-labs/api-client-exception": "^1.0",
14-
"ext-intl": "*",
14+
"ext-dom": "*",
15+
"ext-json": "*",
1516
"guzzlehttp/psr7": "^1.6",
1617
"pimple/pimple": "^3.3",
1718
"psr/container": "^1.0",

src/Input/Specification.php

+50
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
namespace DoclerLabs\ApiClientGenerator\Input;
66

77
use cebe\openapi\spec\OpenApi;
8+
use DoclerLabs\ApiClientGenerator\Entity\Constraint\ConstraintInterface;
9+
use DoclerLabs\ApiClientGenerator\Entity\Constraint\MaxLengthConstraint;
10+
use DoclerLabs\ApiClientGenerator\Entity\Constraint\MinLengthConstraint;
11+
use DoclerLabs\ApiClientGenerator\Entity\Field;
812
use DoclerLabs\ApiClientGenerator\Entity\FieldCollection;
913
use DoclerLabs\ApiClientGenerator\Entity\Operation;
1014
use DoclerLabs\ApiClientGenerator\Entity\OperationCollection;
@@ -100,4 +104,50 @@ public function getAllContentTypes(): array
100104

101105
return array_keys(array_filter($allContentTypes));
102106
}
107+
108+
public function requiresIntlExtension(): bool
109+
{
110+
/** @var Operation $operation */
111+
foreach ($this->getOperations() as $operation) {
112+
foreach ($operation->getRequest()->getFields() as $fields) {
113+
/** @var Field $field */
114+
foreach ($fields as $field) {
115+
if ($this->fieldRequiresIntlExtension($field)) {
116+
return true;
117+
}
118+
}
119+
}
120+
}
121+
122+
return false;
123+
}
124+
125+
private function fieldRequiresIntlExtension(Field $field): bool
126+
{
127+
/** @var ConstraintInterface $constraint */
128+
foreach ($field->getConstraints() as $constraint) {
129+
if (
130+
(
131+
$constraint instanceof MinLengthConstraint
132+
|| $constraint instanceof MaxLengthConstraint
133+
)
134+
&& $constraint->exists()
135+
) {
136+
return true;
137+
}
138+
}
139+
140+
if (
141+
$field->isObject()
142+
&& !empty($field->getObjectProperties())
143+
) {
144+
foreach ($field->getObjectProperties() as $field) {
145+
if ($this->fieldRequiresIntlExtension($field)) {
146+
return true;
147+
}
148+
}
149+
}
150+
151+
return false;
152+
}
103153
}

src/Meta/ComposerJsonTemplate.php

+22-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use DoclerLabs\ApiClientGenerator\Generator\Implementation\HttpMessageImplementationStrategy;
99
use DoclerLabs\ApiClientGenerator\Input\Configuration;
1010
use DoclerLabs\ApiClientGenerator\Input\Specification;
11+
use DoclerLabs\ApiClientGenerator\Output\Copy\Serializer\ContentType\JsonContentTypeSerializer;
12+
use DoclerLabs\ApiClientGenerator\Output\Copy\Serializer\ContentType\XmlContentTypeSerializer;
1113
use DoclerLabs\ApiClientGenerator\Output\Meta\MetaFile;
1214
use DoclerLabs\ApiClientGenerator\Output\Meta\MetaFileCollection;
1315
use Twig\Environment;
@@ -40,6 +42,7 @@ public function render(Specification $specification, MetaFileCollection $fileReg
4042
{
4143
$packages = array_merge(
4244
$this->getCommonPackages(),
45+
$this->getPackagesForSpecification($specification),
4346
$this->messageImplementation->getPackages(),
4447
$this->containerImplementation->getPackages()
4548
);
@@ -63,9 +66,27 @@ private function getCommonPackages(): array
6366
{
6467
return [
6568
'docler-labs/api-client-exception' => '^1.0',
66-
'ext-intl' => '*',
6769
'psr/container' => '^1.0',
6870
'psr/http-client' => '^1.0',
6971
];
7072
}
73+
74+
private function getPackagesForSpecification(Specification $specification): array
75+
{
76+
$packages = [];
77+
78+
if ($specification->requiresIntlExtension()) {
79+
$packages['ext-intl'] = '*';
80+
}
81+
82+
if (in_array(JsonContentTypeSerializer::MIME_TYPE, $specification->getAllContentTypes(), true)) {
83+
$packages['ext-json'] = '*';
84+
}
85+
86+
if (in_array(XmlContentTypeSerializer::MIME_TYPE, $specification->getAllContentTypes(), true)) {
87+
$packages['ext-dom'] = '*';
88+
}
89+
90+
return $packages;
91+
}
7192
}

test/suite/functional/Input/SpecificationTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class SpecificationTest extends TestCase
2222
public function testAllContentTypesArrayPopulatedCorrectly(array $data, array $expectedResult): void
2323
{
2424
$specification = $this->sut->parse($data, '/openapi.yaml');
25-
static::assertSame($specification->getAllContentTypes(), $expectedResult);
25+
26+
static::assertSame($expectedResult, $specification->getAllContentTypes());
2627
}
2728

2829
public function contentTypesTestProvider(): array

test/suite/functional/Meta/ComposerJson/composer_default.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"require": {
1111
"php": ">=7.4",
1212
"docler-labs/api-client-exception": "^1.0",
13-
"ext-intl": "*",
13+
"ext-json": "*",
1414
"guzzlehttp/psr7": "^1.6",
1515
"pimple/pimple": "^3.3",
1616
"psr/container": "^1.0",

0 commit comments

Comments
 (0)