@@ -27,8 +27,8 @@ export function getUniquePropertyName(rootModel: CommonModel, propertyName: stri
2727/**
2828 * The common naming convention context type.
2929 */
30- export type CommonTypeNamingConventionCtx = { model : CommonModel , inputModel : CommonInputModel , isReservedKeyword ?: boolean } ;
31- export type CommonPropertyNamingConventionCtx = { model : CommonModel , inputModel : CommonInputModel , property ?: CommonModel , isReservedKeyword ?: boolean } ;
30+ export type CommonTypeNamingConventionCtx = { model : CommonModel , inputModel : CommonInputModel , reservedKeywordCallback ?: ( name : string ) => boolean } ;
31+ export type CommonPropertyNamingConventionCtx = { model : CommonModel , inputModel : CommonInputModel , property ?: CommonModel , reservedKeywordCallback ?: ( name : string ) => boolean } ;
3232
3333/**
3434 * The common naming convention type shared between generators for different languages.
@@ -44,22 +44,24 @@ export type CommonNamingConvention = {
4444export const CommonNamingConventionImplementation : CommonNamingConvention = {
4545 type : ( name , ctx ) => {
4646 if ( ! name ) { return '' ; }
47- if ( ctx . isReservedKeyword ) {
48- name = `reserved_${ name } ` ;
47+ let formattedName = FormatHelpers . toPascalCase ( name ) ;
48+ if ( ctx . reservedKeywordCallback !== undefined && ctx . reservedKeywordCallback ( formattedName ) ) {
49+ formattedName = FormatHelpers . toPascalCase ( `reserved_${ formattedName } ` ) ;
4950 }
50- return FormatHelpers . toPascalCase ( name ) ;
51+ return formattedName ;
5152 } ,
5253 property : ( name , ctx ) => {
5354 if ( ! name ) { return '' ; }
54- if ( ctx . isReservedKeyword ) {
55+ let formattedName = FormatHelpers . toCamelCase ( name ) ;
56+ if ( ctx . reservedKeywordCallback !== undefined && ctx . reservedKeywordCallback ( formattedName ) ) {
5557 // If name is considered reserved, make sure we rename it appropriately
5658 // and make sure no clashes occur.
57- name = FormatHelpers . toCamelCase ( `reserved_${ name } ` ) ;
58- if ( Object . keys ( ctx . model . properties || { } ) . includes ( name ) ) {
59+ formattedName = FormatHelpers . toCamelCase ( `reserved_${ formattedName } ` ) ;
60+ if ( Object . keys ( ctx . model . properties || { } ) . includes ( formattedName ) ) {
5961 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
60- return CommonNamingConventionImplementation . property ! ( name , ctx ) ;
62+ return CommonNamingConventionImplementation . property ! ( `reserved_ ${ formattedName } ` , ctx ) ;
6163 }
6264 }
63- return FormatHelpers . toCamelCase ( name ) ;
65+ return formattedName ;
6466 }
6567} ;
0 commit comments