Skip to content

Commit

Permalink
firstSegmentSplit case application
Browse files Browse the repository at this point in the history
  • Loading branch information
John Carmichael committed Sep 18, 2023
1 parent 4a738bf commit e31345f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/UniqueOperationIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class UniqueOperationIds {
let iterationToNotCaseChange = -1;
if (firstSegmentSplit) {
iterationToNotCaseChange = 0;
filePathParts[0] = filePathParts[0] + firstSegmentSplit;
}

// inject the prefixes if given
Expand All @@ -53,7 +52,7 @@ class UniqueOperationIds {
}

for (let i = 0; i < filePathParts.length; ++i) {
if (filePathParts[i] !== sep && i !== iterationToNotCaseChange) {
if (filePathParts[i] !== sep) {
switch (segmentStyle) {
case StringStyle.snakeCase:
filePathParts[i] = _.snakeCase(this.removeCurlys(filePathParts[i]));
Expand All @@ -72,6 +71,10 @@ class UniqueOperationIds {
if ([StringStyle.camelCase, StringStyle.PascalCase].includes(style)) {
filePathParts[i] = ucFirst(filePathParts[i]);
}
// Add the split highlight
if (i === iterationToNotCaseChange) {
filePathParts[i] += firstSegmentSplit;
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/UniqueOperationIds.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ describe('firstSegmentSplit tests', () => {
).toBe('weather_IsBadGet');
});

it('should separate with -', async () => {
it('should separate with - but also the camel case should be applied to the first segment even though there is a split highlight passed', async () => {
expect(
UniqueOperationIds.getUniqueOperationIdFromPath({
filePath: 'src/paths/weather/is-bad/get.yml',
filePath: 'src/paths/weather-is/bad/get.yml',
stripValue: 'src/paths/',
cwd: 'some/dir/',
firstSegmentSplit: '-'
})
).toBe('weather-IsBadGet');
).toBe('weatherIs-BadGet');
});
});

0 comments on commit e31345f

Please sign in to comment.