Skip to content

Commit 1ae91d7

Browse files
committed
feat: Review
1 parent bbefe7e commit 1ae91d7

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

src/apitypes/rest/rest.operation.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ import {
3737
getSplittedVersionKey,
3838
getSymbolValueIfDefined,
3939
isDeprecatedOperationItem,
40-
isObject,
4140
isOperationDeprecated,
41+
isValidHttpMethod,
4242
normalizePath,
4343
rawToApiKind,
4444
removeFirstSlash,
@@ -297,7 +297,7 @@ function reduceComponentPathItemsToOperations(
297297
}
298298
}
299299

300-
const getPathItemComponentJsonPath = (sourcePathItem: OpenAPIV3.PathItemObject): JsonPath | undefined=> {
300+
const getPathItemComponentJsonPath = (sourcePathItem: OpenAPIV3.PathItemObject): JsonPath | undefined => {
301301
const refs = getSymbolValueIfDefined(sourcePathItem, INLINE_REFS_FLAG) as string[] | undefined
302302
if (!refs || refs.length === 0) {
303303
return undefined
@@ -363,15 +363,11 @@ export const extractCommonPathItemProperties = (
363363
...takeIfDefined({ parameters: pathData?.parameters }),
364364
})
365365

366-
function isValidHttpMethod(method: string): method is OpenAPIV3.HttpMethods {
367-
return (Object.values(OpenAPIV3.HttpMethods) as string[]).includes(method)
368-
}
369-
370-
export function calculateOperationId(
366+
export const calculateOperationId = (
371367
basePath: string,
372368
key: string,
373369
path: string,
374-
): string {
370+
): string => {
375371
const operationPath = basePath + path
376372
return slugify(`${removeFirstSlash(operationPath)}-${key}`)
377373
}

src/strategies/document-group.strategy.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
VersionDocument,
2626
} from '../types'
2727
import { REST_API_TYPE } from '../apitypes'
28-
import { EXPORT_FORMAT_TO_FILE_FORMAT, fromBase64, takeIfDefined, toVersionDocument } from '../utils'
28+
import { EXPORT_FORMAT_TO_FILE_FORMAT, fromBase64, isValidHttpMethod, takeIfDefined, toVersionDocument } from '../utils'
2929
import { OpenAPIV3 } from 'openapi-types'
3030
import { getOperationBasePath } from '../apitypes/rest/rest.utils'
3131
import { VersionRestDocument } from '../apitypes/rest/rest.types'
@@ -148,12 +148,12 @@ function transformDocumentData(versionDocument: VersionDocument): OpenAPIV3.Docu
148148
const pathData = sourceDocument.paths[path]!
149149
const isRefPathData = !!pathData.$ref
150150
resultDocument.paths[path] = isRefPathData
151-
? pathData
152-
: {
153-
...resultDocument.paths[path],
154-
...commonPathItemProperties,
155-
[httpMethod]: { ...pathData[httpMethod] },
156-
}
151+
? pathData
152+
: {
153+
...resultDocument.paths[path],
154+
...commonPathItemProperties,
155+
[httpMethod]: { ...pathData[httpMethod] },
156+
}
157157

158158
resultDocument.components = {
159159
...takeIfDefined({ securitySchemes: sourceComponents?.securitySchemes }),
@@ -176,10 +176,6 @@ function normalizeOpenApi(document: OpenAPIV3.Document, source?: OpenAPIV3.Docum
176176
) as OpenAPIV3.Document
177177
}
178178

179-
function isValidHttpMethod(method: string): method is OpenAPIV3.HttpMethods {
180-
return (Object.values(OpenAPIV3.HttpMethods) as string[]).includes(method)
181-
}
182-
183179
function isNonNullObject(value: unknown): value is Record<string, unknown> {
184180
return typeof value === 'object' && value !== null
185181
}

src/utils/operations.utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { ApiOperation, BuildResult } from '../types'
1818
import { GraphApiComponents, GraphApiDirectiveDefinition } from '@netcracker/qubership-apihub-graphapi'
19-
import type { OpenAPIV3 } from 'openapi-types'
19+
import { OpenAPIV3 } from 'openapi-types'
2020
import { isObject } from './objects'
2121
import { slugify } from './document'
2222
import { removeFirstSlash } from './builder'
@@ -82,3 +82,9 @@ export function isOperationRemove(operationDiff: Diff): boolean {
8282
// length is 2 because json path has view like ['paths', '/test/element']
8383
return operationDiff.action === DiffAction.remove && !!matchPaths(operationDiff.beforeDeclarationPaths, [[OPEN_API_PROPERTY_PATHS, PREDICATE_ANY_VALUE]])
8484
}
85+
86+
const HTTP_METHODS_SET = new Set(Object.values(OpenAPIV3.HttpMethods) as string[])
87+
88+
export const isValidHttpMethod = (method: string): method is OpenAPIV3.HttpMethods => {
89+
return HTTP_METHODS_SET.has(method)
90+
}

0 commit comments

Comments
 (0)