Skip to content

Commit 4afcdbc

Browse files
committed
feat(api-client): when no operation id, method names generated from path and method type
Signed-off-by: Vojtech Masek <vojtech.masek@flowup.cz>
1 parent b09a679 commit 4afcdbc

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/helper.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ export function camelCase(text: string = '', lowerFirst: boolean = true): string
99
return text;
1010
}
1111

12-
const camelText = text.split(/[-._]/).map(word => `${word[0].toUpperCase()}${word.substring(1)}`).join('');
12+
const camelText = text.split(/[-._\/\\+*]/)
13+
.filter(word => !!word) // skip empty words
14+
.map(word => `${word[0].toUpperCase()}${word.substring(1)}`).join('');
1315

1416
return lowerFirst
1517
? /^([A-Z]+(?=[A-Z]))/.test(camelText)

src/parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ function parseMethods({paths, security, parameters}: Swagger): Method[] {
4343
isSecure: security !== undefined || operation.security !== undefined,
4444
methodName: camelCase(operation.operationId
4545
? operation.operationId
46-
: console.error(`Method name could not be determined, path will be used instead of operation id [ ${pathName} ]`) || pathName),
46+
: `${methodType}_${pathName.replace(/[{}]/g, '')}`
47+
),
4748
methodType: methodType.toUpperCase() as MethodType,
4849
parameters: transformParameters(operation.parameters, parameters || {}),
4950
path: pathName.replace(/({.*?})/g, '$$$1'), // turn path interpolation `{this}` into string template `${this}

0 commit comments

Comments
 (0)