Skip to content

Commit 22e50fe

Browse files
committed
Fix bug in camelize method
Model with inline_response_200 name has been camelized to InlineResponseR00 which is obviously wrong.
1 parent f661ced commit 22e50fe

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/Utils/StringUtilsTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ public static function camelize($word, $lowercaseFirstLetter = false)
7474
$original = $matches[2][0];
7575
$upperCase = strtoupper($original);
7676
if ($original === $upperCase) {
77-
$word = preg_replace($p, '$2', $word);
77+
$word = preg_replace($p, '$2', $word, 1);
7878
} else {
79-
$word = preg_replace($p, $upperCase, $word);
79+
$word = preg_replace($p, $upperCase, $word, 1);
8080
}
8181
}
8282

8383
// Remove all hyphens (hyphen-case to camelCase)
8484
$p = '/(-)(.)/';
8585
while (preg_match($p, $word, $matches) === 1) {
8686
$upperCase = strtoupper($matches[2][0]);
87-
$word = preg_replace($p, $upperCase, $word);
87+
$word = preg_replace($p, $upperCase, $word, 1);
8888
}
8989

9090
if ($lowercaseFirstLetter === true && strlen($word) > 0) {

test/Utils/ModelUtilsTraitTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ public function provideRefs()
6868
'number as argument' => [
6969
156, null,
7070
],
71+
'inline response 200' => [
72+
'#/components/schemas/inline_response_200', 'inline_response_200',
73+
],
7174
];
7275
}
7376

@@ -97,6 +100,7 @@ public function provideModelNames()
97100
['abcd', 'WithStart', 'AndEnd', 'WithStartAbcdAndEnd'],
98101
['_foobar_Objects', null, null, 'FoobarObjects'],
99102
[null, null, null, null],
103+
['inline_response_200', null, null, 'InlineResponse200'],
100104
];
101105
}
102106
}

test/Utils/StringUtilsTraitTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public function provideWordsForCamelizeTest()
6767

6868
['123', true, '123'],
6969
['$123', true, '$123'],
70+
['_foobar_Objects', null, 'FoobarObjects'],
71+
['_foobar_Objects_small_Big', null, 'FoobarObjectsSmallBig'],
72+
['inline_response_200', null, 'InlineResponse200'],
7073
];
7174
}
7275

0 commit comments

Comments
 (0)