Skip to content

Commit 66af9d8

Browse files
committed
feat: Cleaning
1 parent 665fec8 commit 66af9d8

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/apitypes/rest/rest.operation.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,12 @@ export function createSinglePathItemOperationSpec(
283283
sourcePathItem?.servers ||
284284
[],
285285
)
286-
287-
const operationPath = basePath + path
288-
const operationId = slugify(`${removeFirstSlash(operationPath)}-${httpMethod}`)
286+
const operationId = getOperationId(basePath, httpMethod, path)
289287
return operations.includes(operationId)
290288
})
291289

292290
if (operationIds?.length) {
293-
const pathItem = {
291+
const pathItemObject = {
294292
...extractCommonPathItemProperties(valueByPath),
295293
...operationIds.reduce<OpenAPIV3.PathItemObject>((pathItemObject: OpenAPIV3.PathItemObject, operationId: OpenAPIV3.HttpMethods) => {
296294
const operationData = valueByPath[operationId]
@@ -300,7 +298,7 @@ export function createSinglePathItemOperationSpec(
300298
return pathItemObject
301299
}, {}),
302300
}
303-
setValueByPath(sourceDocument, richReference.jsonPath, pathItem)
301+
setValueByPath(sourceDocument, richReference.jsonPath, pathItemObject)
304302
}
305303
}
306304
}
@@ -374,3 +372,12 @@ export const extractCommonPathItemProperties = (
374372
function isValidHttpMethod(method: string): method is OpenAPIV3.HttpMethods {
375373
return (Object.values(OpenAPIV3.HttpMethods) as string[]).includes(method)
376374
}
375+
376+
export function getOperationId(
377+
basePath: string,
378+
key: string,
379+
path: string,
380+
): string {
381+
const operationPath = basePath + path
382+
return slugify(`${removeFirstSlash(operationPath)}-${key}`)
383+
}

src/apitypes/rest/rest.operations.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616

1717
import { OpenAPIV3 } from 'openapi-types'
1818

19-
import { buildRestOperation } from './rest.operation'
19+
import { buildRestOperation, getOperationId } from './rest.operation'
2020
import { OperationIdNormalizer, OperationsBuilder } from '../../types'
2121
import {
2222
createBundlingErrorHandler,
2323
IGNORE_PATH_PARAM_UNIFIED_PLACEHOLDER,
2424
removeComponents,
25-
removeFirstSlash,
2625
slugify,
2726
} from '../../utils'
2827
import { getOperationBasePath } from './rest.utils'
@@ -77,9 +76,8 @@ export const buildRestOperations: OperationsBuilder<OpenAPIV3.Document> = async
7776
await asyncFunction(() => {
7877
const methodData = pathData[key as OpenAPIV3.HttpMethods]
7978
const basePath = getOperationBasePath(methodData?.servers || pathData?.servers || servers || [])
80-
const operationPath = basePath + path
8179

82-
const operationId = slugify(`${removeFirstSlash(operationPath)}-${key}`)
80+
const operationId = getOperationId(basePath, key, path)
8381

8482
if (ctx.operationResolver(operationId)) {
8583
ctx.notifications.push({

0 commit comments

Comments
 (0)