mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
Better cleanup of service and operation names
This commit is contained in:
parent
245afe6a15
commit
107895a7fd
@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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');
|
||||
});
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@ -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`;
|
||||
|
||||
@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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');
|
||||
});
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@ -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
@ -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
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user