Skip to content

Commit abe073d

Browse files
committed
fix(generator): toCamelCase method removes duplicate words
duplicate words are removed recursively in multiple runs until all are removed
1 parent 43fdf61 commit abe073d

File tree

62 files changed

+1196
-1170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1196
-1170
lines changed

src/helper.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ export function toCamelCase(
1111
text: string = '',
1212
lowerFirst: boolean = true,
1313
): string {
14-
text = removeDuplicateWords(text);
15-
1614
if (/^[A-Z0-9]+$/.test(text) || text === '') {
1715
return text;
1816
}
@@ -23,13 +21,15 @@ export function toCamelCase(
2321
.map(word => `${word[0].toUpperCase()}${word.substring(1)}`)
2422
.join('');
2523

26-
return lowerFirst
27-
? /^([A-Z]+(?=[A-Z]))/.test(camelText)
28-
? camelText.replace(/^([A-Z]+(?=[A-Z]))/, firstWord =>
29-
firstWord.toLowerCase(),
30-
)
31-
: `${camelText[0].toLowerCase()}${camelText.substring(1)}`
32-
: camelText;
24+
return removeDuplicateWords(
25+
lowerFirst
26+
? /^([A-Z]+(?=[A-Z]))/.test(camelText)
27+
? camelText.replace(/^([A-Z]+(?=[A-Z]))/, firstWord =>
28+
firstWord.toLowerCase(),
29+
)
30+
: `${camelText[0].toLowerCase()}${camelText.substring(1)}`
31+
: camelText,
32+
);
3333
}
3434

3535
export function dashCase(text: string = ''): string {
@@ -63,7 +63,13 @@ export function dereferenceType(refString: string | undefined): string {
6363
* @returns {string}
6464
*/
6565
export function removeDuplicateWords(text: string = ''): string {
66-
return text.replace(/(.{3,})(?=\1)/gi, '');
66+
const next = text.replace(/(.{3,})(?=\1)/gi, '');
67+
68+
if (next !== text) {
69+
removeDuplicateWords(next);
70+
}
71+
72+
return next;
6773
}
6874

6975
export function toTypescriptType(type: string | undefined): string {
@@ -103,7 +109,7 @@ export function fileName(name: string = '', type: FileInfix = 'model'): string {
103109
}
104110

105111
export function prefixImportedModels(type: string = ''): string {
106-
return BUILD_IN_TS_TYPE_REGEX.test(type) ? type : `models.${type}`;
112+
return BUILD_IN_TS_TYPE_REGEX.test(type) ? type : `models.${typeName(type)}`;
107113
}
108114

109115
export function replaceNewLines(

tests/github/api/guards/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export { isTree } from './tree.guard';
118118
export { isTrees } from './trees.guard';
119119
export { isUser } from './user.guard';
120120
export { isUserEmails } from './user-emails.guard';
121+
export { isUserIdSubscribitions } from './user-id-subscribitions.guard';
121122
export { isUserKeysKeyId } from './user-keys-key-id.guard';
122123
export { isUserKeysPost } from './user-keys-post.guard';
123124
export { isUsers } from './users.guard';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* tslint:disable */
2+
import {
3+
UserIdSubscribitions,
4+
} from '../models';
5+
6+
export function isUserIdSubscribitions(arg: any): arg is UserIdSubscribitions {
7+
return (
8+
arg != null &&
9+
typeof arg === 'object' &&
10+
11+
true
12+
);
13+
}
14+

tests/github/api/models/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export { Tree } from './tree.model';
118118
export { Trees } from './trees.model';
119119
export { User } from './user.model';
120120
export { UserEmails } from './user-emails.model';
121+
export { UserIdSubscribitions } from './user-id-subscribitions.model';
121122
export { UserKeysKeyId } from './user-keys-key-id.model';
122123
export { UserKeysPost } from './user-keys-post.model';
123124
export { Users } from './users.model';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* tslint:disable */
2+
3+
export interface UserIdSubscribitions {
4+
}

tests/github/api/services/emojis/emojis-api-client.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface EmojisAPIClientInterface {
1414
args: {
1515
xGitHubMediaType?: string, // (optional) You can check the current version of media type in responses.
1616
accept?: string, // (optional) Is used to set specified media type.
17-
xRateLimitLimit?: number,
17+
xRateLimit?: number,
1818
xRateLimitRemaining?: number,
1919
xRateLimitReset?: number,
2020
xGitHubRequestId?: number,

tests/github/api/services/emojis/emojis-api-client.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class EmojisAPIClient implements EmojisAPIClientInterface {
5050
args: {
5151
xGitHubMediaType?: string, // (optional) You can check the current version of media type in responses.
5252
accept?: string, // (optional) Is used to set specified media type.
53-
xRateLimitLimit?: number,
53+
xRateLimit?: number,
5454
xRateLimitRemaining?: number,
5555
xRateLimitReset?: number,
5656
xGitHubRequestId?: number,
@@ -69,8 +69,8 @@ export class EmojisAPIClient implements EmojisAPIClientInterface {
6969
if ('accept' in args) {
7070
options.headers = options.headers.set('Accept', String(args.accept));
7171
}
72-
if ('xRateLimitLimit' in args) {
73-
options.headers = options.headers.set('X-RateLimit-Limit', String(args.xRateLimitLimit));
72+
if ('xRateLimit' in args) {
73+
options.headers = options.headers.set('X-RateLimit-Limit', String(args.xRateLimit));
7474
}
7575
if ('xRateLimitRemaining' in args) {
7676
options.headers = options.headers.set('X-RateLimit-Remaining', String(args.xRateLimitRemaining));

tests/github/api/services/emojis/guarded-emojis-api-client.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class GuardedEmojisAPIClient extends EmojisAPIClient {
2626
args: {
2727
xGitHubMediaType?: string, // (optional) You can check the current version of media type in responses.
2828
accept?: string, // (optional) Is used to set specified media type.
29-
xRateLimitLimit?: number,
29+
xRateLimit?: number,
3030
xRateLimitRemaining?: number,
3131
xRateLimitReset?: number,
3232
xGitHubRequestId?: number,

tests/github/api/services/events/events-api-client.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface EventsAPIClientInterface {
1414
args: {
1515
xGitHubMediaType?: string, // (optional) You can check the current version of media type in responses.
1616
accept?: string, // (optional) Is used to set specified media type.
17-
xRateLimitLimit?: number,
17+
xRateLimit?: number,
1818
xRateLimitRemaining?: number,
1919
xRateLimitReset?: number,
2020
xGitHubRequestId?: number,

tests/github/api/services/events/events-api-client.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class EventsAPIClient implements EventsAPIClientInterface {
5050
args: {
5151
xGitHubMediaType?: string, // (optional) You can check the current version of media type in responses.
5252
accept?: string, // (optional) Is used to set specified media type.
53-
xRateLimitLimit?: number,
53+
xRateLimit?: number,
5454
xRateLimitRemaining?: number,
5555
xRateLimitReset?: number,
5656
xGitHubRequestId?: number,
@@ -69,8 +69,8 @@ export class EventsAPIClient implements EventsAPIClientInterface {
6969
if ('accept' in args) {
7070
options.headers = options.headers.set('Accept', String(args.accept));
7171
}
72-
if ('xRateLimitLimit' in args) {
73-
options.headers = options.headers.set('X-RateLimit-Limit', String(args.xRateLimitLimit));
72+
if ('xRateLimit' in args) {
73+
options.headers = options.headers.set('X-RateLimit-Limit', String(args.xRateLimit));
7474
}
7575
if ('xRateLimitRemaining' in args) {
7676
options.headers = options.headers.set('X-RateLimit-Remaining', String(args.xRateLimitRemaining));

0 commit comments

Comments
 (0)