Better cleanup of service and operation names

This commit is contained in:
Ferdi Koomen 2020-10-15 00:15:13 +02:00
parent 245afe6a15
commit 107895a7fd
15 changed files with 425 additions and 308 deletions

View File

@ -9,5 +9,10 @@ describe('getOperationName', () => {
expect(getOperationName('foo-bar')).toEqual('fooBar');
expect(getOperationName('foo_bar')).toEqual('fooBar');
expect(getOperationName('foo.bar')).toEqual('fooBar');
expect(getOperationName('@foo.bar')).toEqual('fooBar');
expect(getOperationName('$foo.bar')).toEqual('fooBar');
expect(getOperationName('_foo.bar')).toEqual('fooBar');
expect(getOperationName('-foo.bar')).toEqual('fooBar');
expect(getOperationName('123.foo.bar')).toEqual('fooBar');
});
});

View File

@ -6,6 +6,9 @@ import camelCase from 'camelcase';
* the most popular Javascript and Typescript writing style.
*/
export function getOperationName(value: string): string {
const clean = value.replace(/[^\w\s\-]+/g, '-').trim();
const clean = value
.replace(/^[^a-zA-Z]+/g, '')
.replace(/[^\w\-]+/g, '-')
.trim();
return camelCase(clean);
}

View File

@ -5,9 +5,12 @@ describe('getOperationParameterName', () => {
expect(getOperationParameterName('')).toEqual('');
expect(getOperationParameterName('foobar')).toEqual('foobar');
expect(getOperationParameterName('fooBar')).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('fooBar');
expect(getOperationParameterName('@foo.bar')).toEqual('fooBar');
expect(getOperationParameterName('$foo.bar')).toEqual('fooBar');
expect(getOperationParameterName('123.foo.bar')).toEqual('fooBar');
expect(getOperationParameterName('Foo-Bar')).toEqual('fooBar');
expect(getOperationParameterName('FOO-BAR')).toEqual('fooBar');
});

View File

@ -5,6 +5,9 @@ import camelCase from 'camelcase';
* For example: 'filter.someProperty' becomes 'filterSomeProperty'.
*/
export function getOperationParameterName(value: string): string {
const clean = value.replace(/[^\w\s\-]+/g, '-').trim();
const clean = value
.replace(/^[^a-zA-Z]+/g, '')
.replace(/[^\w\-]+/g, '-')
.trim();
return camelCase(clean);
}

View File

@ -9,5 +9,8 @@ describe('getServiceClassName', () => {
expect(getServiceClassName('FooBarService')).toEqual('FooBarService');
expect(getServiceClassName('Foo Bar Service')).toEqual('FooBarService');
expect(getServiceClassName('foo bar service')).toEqual('FooBarService');
expect(getServiceClassName('@fooBar')).toEqual('FooBarService');
expect(getServiceClassName('$fooBar')).toEqual('FooBarService');
expect(getServiceClassName('123fooBar')).toEqual('FooBarService');
});
});

View File

@ -5,7 +5,10 @@ import camelCase from 'camelcase';
* the input string to PascalCase and appends the "Service" prefix if needed.
*/
export function getServiceClassName(value: string): string {
const clean = value.replace(/[^\w\s\-]+/g, '-').trim();
const clean = value
.replace(/^[^a-zA-Z]+/g, '')
.replace(/[^\w\-]+/g, '-')
.trim();
const name = camelCase(clean, { pascalCase: true });
if (name && !name.endsWith('Service')) {
return `${name}Service`;

View File

@ -9,5 +9,10 @@ describe('getOperationName', () => {
expect(getOperationName('foo-bar')).toEqual('fooBar');
expect(getOperationName('foo_bar')).toEqual('fooBar');
expect(getOperationName('foo.bar')).toEqual('fooBar');
expect(getOperationName('@foo.bar')).toEqual('fooBar');
expect(getOperationName('$foo.bar')).toEqual('fooBar');
expect(getOperationName('_foo.bar')).toEqual('fooBar');
expect(getOperationName('-foo.bar')).toEqual('fooBar');
expect(getOperationName('123.foo.bar')).toEqual('fooBar');
});
});

View File

@ -6,6 +6,9 @@ import camelCase from 'camelcase';
* the most popular Javascript and Typescript writing style.
*/
export function getOperationName(value: string): string {
const clean = value.replace(/[^\w\s\-]+/g, '-').trim();
const clean = value
.replace(/^[^a-zA-Z]+/g, '')
.replace(/[^\w\-]+/g, '-')
.trim();
return camelCase(clean);
}

View File

@ -5,9 +5,12 @@ describe('getOperationParameterName', () => {
expect(getOperationParameterName('')).toEqual('');
expect(getOperationParameterName('foobar')).toEqual('foobar');
expect(getOperationParameterName('fooBar')).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('fooBar');
expect(getOperationParameterName('@foo.bar')).toEqual('fooBar');
expect(getOperationParameterName('$foo.bar')).toEqual('fooBar');
expect(getOperationParameterName('123.foo.bar')).toEqual('fooBar');
expect(getOperationParameterName('Foo-Bar')).toEqual('fooBar');
expect(getOperationParameterName('FOO-BAR')).toEqual('fooBar');
});

View File

@ -5,6 +5,9 @@ import camelCase from 'camelcase';
* For example: 'filter.someProperty' becomes 'filterSomeProperty'.
*/
export function getOperationParameterName(value: string): string {
const clean = value.replace(/[^\w\s\-]+/g, '-').trim();
const clean = value
.replace(/^[^a-zA-Z]+/g, '')
.replace(/[^\w\-]+/g, '-')
.trim();
return camelCase(clean);
}

View File

@ -9,5 +9,8 @@ describe('getServiceClassName', () => {
expect(getServiceClassName('FooBarService')).toEqual('FooBarService');
expect(getServiceClassName('Foo Bar Service')).toEqual('FooBarService');
expect(getServiceClassName('foo bar service')).toEqual('FooBarService');
expect(getServiceClassName('@fooBar')).toEqual('FooBarService');
expect(getServiceClassName('$fooBar')).toEqual('FooBarService');
expect(getServiceClassName('123fooBar')).toEqual('FooBarService');
});
});

View File

@ -5,7 +5,10 @@ import camelCase from 'camelcase';
* the input string to PascalCase and appends the "Service" prefix if needed.
*/
export function getServiceClassName(value: string): string {
const clean = value.replace(/[^\w\s\-]+/g, '-').trim();
const clean = value
.replace(/^[^a-zA-Z]+/g, '')
.replace(/[^\w\-]+/g, '-')
.trim();
const name = camelCase(clean, { pascalCase: true });
if (name && !name.endsWith('Service')) {
return `${name}Service`;

File diff suppressed because it is too large Load Diff

View File

@ -434,6 +434,29 @@
"$ref": "#/definitions/ModelWithString"
}
},
"200": {
"description": "Message for 200 response",
"schema": {
"type": "object",
"properties": {
"@namespace.string": {
"type": "string",
"readOnly": true
},
"@namespace.integer": {
"type": "integer",
"readOnly": true
},
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/ModelWithString"
},
"readOnly": true
}
}
}
},
"201": {
"description": "Message for 201 response",
"schema": {
@ -1050,6 +1073,14 @@
},
"reference": {
"$ref": "#/definitions/ModelWithString"
},
"@namespace.string": {
"type": "string",
"readOnly": true
},
"@namespace.integer": {
"type": "integer",
"readOnly": true
}
}
},

View File

@ -632,6 +632,33 @@
}
}
},
"200": {
"description": "Message for 200 response",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"@namespace.string": {
"type": "string",
"readOnly": true
},
"@namespace.integer": {
"type": "integer",
"readOnly": true
},
"value": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ModelWithString"
},
"readOnly": true
}
}
}
}
}
},
"201": {
"description": "Message for 201 response",
"content": {
@ -1558,6 +1585,14 @@
},
"reference": {
"$ref": "#/components/schemas/ModelWithString"
},
"@namespace.string": {
"type": "string",
"readOnly": true
},
"@namespace.integer": {
"type": "integer",
"readOnly": true
}
}
},