mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
Merge pull request #1067 from kulczy/arrays
Prevent duplication of parameter names
This commit is contained in:
commit
d5ca21c64e
@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,6 +9,7 @@ import { reservedWords } from '../../../utils/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