Skip to content

Commit 2c83aa2

Browse files
committed
refactor: extract method to calculateNormalizedOperationId
1 parent c1c2345 commit 2c83aa2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/apitypes/rest/rest.changes.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ import {
6666
} from './rest.utils'
6767
import { createOperationChange, getOperationTags, OperationsMap } from '../../components'
6868

69+
/**
70+
* Calculates a normalized operation ID for an operation.
71+
*
72+
* @param basePath - The base path from servers configuration
73+
* @param path - The operation path
74+
* @param method - The HTTP method
75+
* @returns The normalized operation ID
76+
*/
77+
function calculateNormalizedOperationId(basePath: string, path: string, method: string): string {
78+
return slugify(`${normalizePath(basePath + path)}-${method}`, [], IGNORE_PATH_PARAM_UNIFIED_PLACEHOLDER)
79+
}
80+
6981
export const compareDocuments = async (
7082
operationsMap: OperationsMap,
7183
prevDoc: ResolvedVersionDocument | undefined,
@@ -140,8 +152,8 @@ export const compareDocuments = async (
140152
// todo if there were actually servers here, we wouldn't have handle it, add a test
141153
const previousBasePath = getOperationBasePath(methodData?.servers || pathData?.servers || prevDocData.servers || [])
142154
const currentBasePath = getOperationBasePath(methodData?.servers || pathData?.servers || currDocData.servers || [])
143-
const prevNormalizedOperationId = slugify(`${normalizePath(previousBasePath + path)}-${inferredMethod}`, [], IGNORE_PATH_PARAM_UNIFIED_PLACEHOLDER)
144-
const currNormalizedOperationId = slugify(`${normalizePath(currentBasePath + path)}-${inferredMethod}`, [], IGNORE_PATH_PARAM_UNIFIED_PLACEHOLDER)
155+
const prevNormalizedOperationId = calculateNormalizedOperationId(previousBasePath, path, inferredMethod)
156+
const currNormalizedOperationId = calculateNormalizedOperationId(currentBasePath, path, inferredMethod)
145157

146158
const { current, previous } = operationsMap[prevNormalizedOperationId] ?? operationsMap[currNormalizedOperationId] ?? {}
147159
if (!current && !previous) {

0 commit comments

Comments
 (0)