Skip to content

Commit 91c4220

Browse files
authored
Merge pull request #129 from php-api-clients/camel-case
Camel case
2 parents 4918ac9 + 3fcd2b5 commit 91c4220

File tree

6 files changed

+24
-3
lines changed

6 files changed

+24
-3
lines changed

src/Gatherer/Operation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public static function gather(
4141
], implode('|', is_array($parameter->schema->type) ? $parameter->schema->type : [$parameter->schema->type]));
4242

4343
$parameters[] = new Parameter(
44+
(new Convert($parameter->name))->toCamel(),
4445
$parameter->name,
4546
(string)$parameter->description,
4647
$parameterType,

src/Gatherer/Property.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use ApiClients\Tools\OpenApiClientGenerator\Representation\PropertyType;
77
use cebe\openapi\spec\Schema as baseSchema;
88
use Ckr\Util\ArrayMerger;
9+
use Jawira\CaseConverter\Convert;
910
use Ramsey\Uuid\Uuid;
1011

1112
final class Property
@@ -57,7 +58,14 @@ public static function gather(
5758
}
5859
$exampleData = self::generateExampleData($exampleData, $type, $propertyName);
5960

60-
return new \ApiClients\Tools\OpenApiClientGenerator\Representation\Property($propertyName, $property->description ?? '', $exampleData, [$type], $type->nullable);
61+
return new \ApiClients\Tools\OpenApiClientGenerator\Representation\Property(
62+
(new Convert($propertyName))->toCamel(),
63+
$propertyName,
64+
$property->description ?? '',
65+
$exampleData,
66+
[$type],
67+
$type->nullable
68+
);
6169
}
6270

6371
private static function generateExampleData(mixed $exampleData, PropertyType $type, string $propertyName): mixed

src/Generator/Operation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ public static function generate(string $namespace, \ApiClients\Tools\OpenApiClie
134134
)
135135
);
136136
if ($parameter->location === 'path' || $parameter->location === 'query') {
137-
$requestReplaces['{' . $parameter->name . '}'] = new Node\Expr\PropertyFetch(
137+
$requestReplaces['{' . $parameter->targetName . '}'] = new Node\Expr\PropertyFetch(
138138
new Node\Expr\Variable('this'),
139139
$parameter->name
140140
);
141141
}
142142
if ($parameter->location === 'query') {
143-
$query[] = $parameter->name . '={' . $parameter->name . '}';
143+
$query[] = $parameter->name . '={' . $parameter->targetName . '}';
144144
}
145145
}
146146
$requestParameters = [

src/Generator/Schema.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ public static function generate(string $namespace, \ApiClients\Tools\OpenApiClie
8989
}
9090

9191
$constructorParam = new PromotedPropertyAsParam($property->name);
92+
if ($property->name !== $property->sourceName) {
93+
$constructorParam->addAttribute(
94+
new Node\Attribute(
95+
new Node\Name('\\' . \EventSauce\ObjectHydrator\MapFrom::class),
96+
[
97+
new Node\Arg(new Node\Scalar\String_($property->sourceName)),
98+
],
99+
),
100+
);
101+
}
92102

93103
$types = [];
94104
foreach ($property->type as $type) {

src/Representation/Parameter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ final class Parameter
66
{
77
public function __construct(
88
public readonly string $name,
9+
public readonly string $targetName,
910
public readonly string $description,
1011
public readonly string $type,
1112
public readonly string $location,

src/Representation/Property.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ final class Property
66
{
77
public function __construct(
88
public readonly string $name,
9+
public readonly string $sourceName,
910
public readonly string $description,
1011
public readonly mixed $exampleData,
1112
/** @var array<PropertyType> */

0 commit comments

Comments
 (0)