mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
Prevent duplication of parameter names
This commit is contained in:
parent
a199552350
commit
a5f6367f78
@ -13,5 +13,7 @@ describe('getOperationParameterName', () => {
|
||||
expect(getOperationParameterName('123.foo.bar')).toEqual('fooBar');
|
||||
expect(getOperationParameterName('Foo-Bar')).toEqual('fooBar');
|
||||
expect(getOperationParameterName('FOO-BAR')).toEqual('fooBar');
|
||||
expect(getOperationParameterName('foo[bar]')).toEqual('fooBar');
|
||||
expect(getOperationParameterName('foo.bar[]')).toEqual('fooBarArray');
|
||||
});
|
||||
});
|
||||
|
||||
@ -10,6 +10,7 @@ const reservedWords =
|
||||
export const getOperationParameterName = (value: string): string => {
|
||||
const clean = value
|
||||
.replace(/^[^a-zA-Z]+/g, '')
|
||||
.replace('[]', 'Array')
|
||||
.replace(/[^\w\-]+/g, '-')
|
||||
.trim();
|
||||
return camelCase(clean).replace(reservedWords, '_$1');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user