Skip to content

Commit 6215150

Browse files
authored
Merge pull request #157 from php-api-clients/add-non-fancy-output-for-ci
Add non-fancy output for CI
2 parents 4b29bc1 + f7113fc commit 6215150

17 files changed

+300
-183
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"league/openapi-psr7-validator": "^0.21",
2323
"nikic/php-parser": "^4.15",
2424
"nunomaduro/termwind": "^1.15",
25+
"ondram/ci-detector": "^4.1",
2526
"pointybeard/reverse-regex": "1.0.0.3",
2627
"psr/http-message": "^1.0",
2728
"react/async": "^4.0",

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Gatherer/Operation.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static function gather(
5050
): \ApiClients\Tools\OpenApiClientGenerator\Representation\Operation {
5151
$returnType = [];
5252
$parameters = [];
53-
$empties = [];
53+
$empties = [];
5454
foreach ($operation->parameters as $parameter) {
5555
$parameterType = str_replace([
5656
'integer',
@@ -70,7 +70,7 @@ public static function gather(
7070
$parameter->schema->format,
7171
$parameter->in,
7272
$parameter->schema->default,
73-
ExampleData::scalarData(strlen($parameter->name),$parameterType, $parameter->schema->format),
73+
ExampleData::scalarData(strlen($parameter->name), $parameterType, $parameter->schema->format),
7474
);
7575
}
7676

@@ -91,7 +91,7 @@ public static function gather(
9191

9292
$response = [];
9393
foreach ($operation->responses ?? [] as $code => $spec) {
94-
$isError = $code >= 400;
94+
$isError = $code >= 400;
9595
$contentCount = 0;
9696
foreach ($spec->content as $contentType => $contentTypeMediaType) {
9797
$contentCount++;
@@ -126,22 +126,24 @@ public static function gather(
126126
$returnType[] = $responseClassname;
127127
}
128128

129-
if ($contentCount === 0) {
130-
$headers = [];
131-
foreach ($spec->headers as $headerName => $headerSpec) {
132-
$headers[$headerName] = new Header($headerName, Schema::gather(
133-
$baseNamespace,
134-
$schemaRegistry->get(
135-
$headerSpec->schema,
136-
'WebHookHeader\\' . ucfirst(preg_replace('/\PL/u', '', $headerName)),
137-
),
138-
$headerSpec->schema,
139-
$schemaRegistry
140-
), ExampleData::determiteType($headerSpec->example));
141-
}
129+
if ($contentCount !== 0) {
130+
continue;
131+
}
142132

143-
$empties[] = new OperationEmptyResponse($code, $spec->description, $headers);
133+
$headers = [];
134+
foreach ($spec->headers as $headerName => $headerSpec) {
135+
$headers[$headerName] = new Header($headerName, Schema::gather(
136+
$baseNamespace,
137+
$schemaRegistry->get(
138+
$headerSpec->schema,
139+
'WebHookHeader\\' . ucfirst(preg_replace('/\PL/u', '', $headerName)),
140+
),
141+
$headerSpec->schema,
142+
$schemaRegistry
143+
), ExampleData::determiteType($headerSpec->example));
144144
}
145+
146+
$empties[] = new OperationEmptyResponse($code, $spec->description, $headers);
145147
}
146148

147149
if (count($returnType) === 0) {

src/Gatherer/OperationHydrator.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use ApiClients\Tools\OpenApiClientGenerator\Configuration\Namespace_;
88
use ApiClients\Tools\OpenApiClientGenerator\Representation\Operation;
9+
use ApiClients\Tools\OpenApiClientGenerator\Representation\Schema;
910

1011
final class OperationHydrator
1112
{
@@ -18,10 +19,12 @@ public static function gather(
1819

1920
foreach ($operations as $operation) {
2021
foreach ($operation->response as $response) {
21-
if ($response->content->payload instanceof \ApiClients\Tools\OpenApiClientGenerator\Representation\Schema) {
22-
foreach (HydratorUtils::listSchemas($response->content->payload) as $schema) {
23-
$schemaClasses[] = $schema;
24-
}
22+
if (! ($response->content->payload instanceof Schema)) {
23+
continue;
24+
}
25+
26+
foreach (HydratorUtils::listSchemas($response->content->payload) as $schema) {
27+
$schemaClasses[] = $schema;
2528
}
2629
}
2730
}

src/Gatherer/Property.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66

77
use ApiClients\Tools\OpenApiClientGenerator\Configuration\Namespace_;
88
use ApiClients\Tools\OpenApiClientGenerator\Registry\Schema as SchemaRegistry;
9+
use ApiClients\Tools\OpenApiClientGenerator\Representation;
910
use cebe\openapi\spec\Schema as baseSchema;
1011
use Jawira\CaseConverter\Convert;
11-
use ApiClients\Tools\OpenApiClientGenerator\Representation;
12-
use PhpParser\Node;
1312
use NumberToWords\NumberToWords;
13+
use PhpParser\Node;
1414

1515
use function array_filter;
1616
use function array_values;
1717
use function count;
18+
use function is_array;
1819
use function preg_replace_callback;
20+
use function str_pad;
1921
use function str_replace;
2022
use function strlen;
2123

@@ -90,13 +92,13 @@ static function ($matches) {
9092
}
9193

9294
if ($property->type === 'array' && is_array($type->payload)) {
93-
$arrayItemsRaw = [];
95+
$arrayItemsRaw = [];
9496
$arrayItemsNode = [];
9597

9698
foreach ($type->payload as $index => $arrayItem) {
9799
$arrayItemExampleData = ExampleData::gather($exampleData, $arrayItem, $propertyName . str_pad('', $index + 1, '_'));
98-
$arrayItemsRaw[] = $arrayItemExampleData->raw;
99-
$arrayItemsNode[] = new Node\Expr\ArrayItem($arrayItemExampleData->node);
100+
$arrayItemsRaw[] = $arrayItemExampleData->raw;
101+
$arrayItemsNode[] = new Node\Expr\ArrayItem($arrayItemExampleData->node);
100102
}
101103

102104
$exampleData = new Representation\ExampleData($arrayItemsRaw, new Node\Expr\Array_($arrayItemsNode));

src/Gatherer/Type.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use function in_array;
1818
use function is_array;
1919
use function is_string;
20+
use function range;
2021
use function str_replace;
2122

2223
final class Type
@@ -169,7 +170,7 @@ public static function gather(
169170
if ($type === 'array') {
170171
$arrayItems = [];
171172

172-
foreach (range(0, ($property->maxItems ?? $property->minItems ?? 2) -1) as $index) {
173+
foreach (range(0, ($property->maxItems ?? $property->minItems ?? 2) - 1) as $index) {
173174
$arrayItems[] = self::gather(
174175
$baseNamespace,
175176
$className,

src/Generator.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use cebe\openapi\Reader;
3030
use cebe\openapi\spec\OpenApi;
3131
use EventSauce\ObjectHydrator\ObjectMapperUsingReflection;
32+
use OndraM\CiDetector\CiDetector;
3233
use PhpParser\Node;
3334
use PhpParser\PrettyPrinter\Standard;
3435
use RuntimeException;
@@ -49,6 +50,7 @@
4950
use function is_string;
5051
use function ltrim;
5152
use function md5;
53+
use function realpath;
5254
use function Safe\file_get_contents;
5355
use function Safe\file_put_contents;
5456
use function Safe\json_decode;
@@ -57,6 +59,7 @@
5759
use function Safe\unlink;
5860
use function str_replace;
5961
use function strlen;
62+
use function strpos;
6063
use function trim;
6164
use function usleep;
6265
use function WyriHaximus\Twig\render;
@@ -81,6 +84,7 @@ public function __construct(
8184
$this->forceGeneration = is_string(getenv('FORCE_GENERATION')) && strlen(getenv('FORCE_GENERATION')) > 0;
8285

8386
$this->statusOutput = new StatusOutput(
87+
! (new CiDetector())->isCiDetected(),
8488
new Step('hash_current_spec', 'Hashing current spec', false),
8589
new Step('loading_state', 'Loading state', false),
8690
new Step('loading_spec', 'Loading spec', false),
@@ -106,14 +110,13 @@ public function __construct(
106110
new Step('generating_templates_files_subsplit_package', 'Generating: Templates Files: SubSplit Packages', true),
107111
new Step('generating_subsplit_configuration', 'Generating: SubSplit Configuration', false),
108112
);
109-
$this->statusOutput->render();
110113

111-
if (!$this->configuration->entryPoints->operations){
114+
if (! $this->configuration->entryPoints->operations) {
112115
$this->statusOutput->markStepWontDo('generating_operationsinterface_entry_point');
113116
$this->statusOutput->markStepWontDo('generating_operations_entry_point');
114117
}
115118

116-
if (!$this->configuration->entryPoints->webHooks){
119+
if (! $this->configuration->entryPoints->webHooks) {
117120
$this->statusOutput->markStepWontDo('generating_webhooks');
118121
$this->statusOutput->markStepWontDo('generating_webhooks_entry_point');
119122
}
@@ -366,8 +369,10 @@ private function all(string $configurationLocation): iterable
366369
);
367370

368371
$this->statusOutput->markStepBusy('client_single');
372+
369373
/** @phpstan-ignore-next-line */
370374
yield from $this->oneClient($configurationLocation, $schemaRegistry, $throwableSchemaRegistry, $schemas, $paths, $webHooks);
375+
371376
$this->statusOutput->markStepDone('client_single');
372377
} else {
373378
$this->statusOutput->markStepWontDo(
@@ -376,8 +381,10 @@ private function all(string $configurationLocation): iterable
376381
);
377382

378383
$this->statusOutput->markStepBusy('client_subsplit');
384+
379385
/** @phpstan-ignore-next-line */
380386
yield from $this->subSplitClient($configurationLocation, $schemaRegistry, $throwableSchemaRegistry, $schemas, $paths, $webHooks);
387+
381388
$this->statusOutput->markStepDone('client_subsplit');
382389
}
383390
}
@@ -803,7 +810,7 @@ private function subSplitClient(
803810
}
804811
}
805812

806-
if (!is_string($split)) {
813+
if (! is_string($split)) {
807814
continue;
808815
}
809816

src/Generator/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
8484
);
8585
}
8686

87-
if ($configuration->entryPoints->webHooks){
87+
if ($configuration->entryPoints->webHooks) {
8888
$class->addStmt(
8989
$factory->property('webHooks')->setType('WebHooks')->makeReadonly()->makePrivate()
9090
);
@@ -260,7 +260,7 @@ public static function generate(Configuration $configuration, string $pathPrefix
260260
]
261261
),
262262
),
263-
] : [])
263+
] : []),
264264
])
265265
);
266266

src/Generator/Operation.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,22 +257,23 @@ public static function generate(string $pathPrefix, \ApiClients\Tools\OpenApiCli
257257
continue;
258258
}
259259

260-
if (!$contentTypeSchema->content->payload instanceof \ApiClients\Tools\OpenApiClientGenerator\Representation\Schema) {
260+
if (! $contentTypeSchema->content->payload instanceof \ApiClients\Tools\OpenApiClientGenerator\Representation\Schema) {
261261
if ($contentTypeSchema->content->type === 'scalar') {
262-
$returnType[] = $returnTypeRaw[] = $contentTypeSchema->content->payload;
262+
$returnType[] = $returnTypeRaw[] = $contentTypeSchema->content->payload;
263263

264264
$caseCases[] = new Node\Stmt\Case_(
265265
new Node\Scalar\LNumber($contentTypeSchema->code),
266266
[
267-
new Node\Stmt\Return_(
268-
new Node\Expr\Variable(
269-
'body',
270-
),
267+
new Node\Stmt\Return_(
268+
new Node\Expr\Variable(
269+
'body',
271270
),
272-
],
271+
),
272+
],
273273
);
274274
continue;
275275
}
276+
276277
continue;
277278
}
278279

@@ -332,7 +333,7 @@ public static function generate(string $pathPrefix, \ApiClients\Tools\OpenApiCli
332333
'SCHEMA_JSON',
333334
)),
334335
new Arg(new Node\Expr\ClassConstFetch(
335-
new Node\Name('\\' . \cebe\openapi\spec\Schema::class),
336+
new Node\Name('\\' . Schema::class),
336337
'class',
337338
)),
338339
])),
@@ -637,7 +638,7 @@ public static function generate(string $pathPrefix, \ApiClients\Tools\OpenApiCli
637638

638639
$returnType[] = 'array{' . implode(',', array_keys($arrayItems)) . '}';
639640
$returnTypeRaw[] = 'array';
640-
$empties[] = new Node\Stmt\Return_(new Node\Expr\Array_(array_values($arrayItems)));
641+
$empties[] = new Node\Stmt\Return_(new Node\Expr\Array_(array_values($arrayItems)));
641642
}
642643

643644
$emptyCase = new Node\Stmt\Case_(

0 commit comments

Comments
 (0)