Skip to content

Commit 2bd568a

Browse files
committed
Fix case conversion for all fields
1 parent 6c68111 commit 2bd568a

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/Case.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Enum } from './client/interfaces/Enum';
12
import { Model } from './client/interfaces/Model';
23

34
export enum Case {
@@ -23,16 +24,19 @@ const transforms = {
2324
// A recursive function that looks at the models and their properties and
2425
// converts each property name using the provided transform function.
2526
export const convertModelNames = (model: Model, type: Exclude<Case, Case.NONE>): Model => {
26-
if (!model.properties.length) {
27-
return {
28-
...model,
29-
name: transforms[type](model.name),
30-
};
31-
}
3227
return {
3328
...model,
34-
properties: model.properties.map(property => {
35-
return convertModelNames(property, type);
36-
}),
29+
name: transforms[type](model.name),
30+
link: model.link ? convertModelNames(model.link, type) : null,
31+
enum: model.enum.map(modelEnum => convertEnumName(modelEnum, type)),
32+
enums: model.enums.map(property => convertModelNames(property, type)),
33+
properties: model.properties.map(property => convertModelNames(property, type)),
34+
};
35+
};
36+
37+
const convertEnumName = (modelEnum: Enum, type: Exclude<Case, Case.NONE>): Enum => {
38+
return {
39+
...modelEnum,
40+
name: transforms[type](modelEnum.name),
3741
};
3842
};

0 commit comments

Comments
 (0)