Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
use snake on discriminator flatten prefix (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
changlong-liu committed May 31, 2021
1 parent 24a9313 commit 49fcffc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/flattener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export class Flattener {
}
if (NodeHelper.getJson(subClass) !== true && !NodeCliHelper.isCliFlattened(polyParam)) {
const path = isNullOrUndefined(polyParam['targetProperty']) ? [] : [polyParam['targetProperty']];
FlattenHelper.flattenParameter(request, polyParam, path, `${discriminatorValue}_`);
FlattenHelper.flattenParameter(request, polyParam, path, `${Helper.camelToSnake(discriminatorValue)}_`);
this.onAfterFlatten(polyParam);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,4 +930,7 @@ export class Helper {
return obj; // Return the top-level object to allow chaining
}

public static camelToSnake(camel: string): string {
return camel.replace(/([A-Z][a-z0-9]+)|([A-Z]+(?=[A-Z][a-z0-9]+))|([A-Z]+$)/g, '_$1$2$3').substr(1).toLowerCase();
}
}
2 changes: 1 addition & 1 deletion src/plugins/m4namer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class M4CommonNamer {
if (!isNullOrUndefined(obj['discriminatorValue'])) {
const dv: string = obj['discriminatorValue'];
// dv should be in pascal format, let's do a simple convert to snake
const newValue = dv.replace(/([A-Z][a-z0-9]+)|([A-Z]+(?=[A-Z][a-z0-9]+))|([A-Z]+$)/g, '_$1$2$3').substr(1).toLowerCase();
const newValue = Helper.camelToSnake(dv);
NodeCliHelper.setCliDiscriminatorValue(obj, newValue);
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/namer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export class CommonNamer {
if (!isNullOrUndefined(obj['discriminatorValue'])) {
const dv: string = obj['discriminatorValue'];
// dv should be in pascal format, let's do a simple convert to snake
const newValue = dv.replace(/([A-Z][a-z0-9]+)|([A-Z]+(?=[A-Z][a-z0-9]+))|([A-Z]+$)/g, '_$1$2$3').substr(1).toLowerCase();
const newValue = Helper.camelToSnake(dv);
NodeCliHelper.setCliDiscriminatorValue(obj, newValue);
}

Expand Down

0 comments on commit 49fcffc

Please sign in to comment.