Skip to content

Commit 1c4e293

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

File tree

6 files changed

+34
-36
lines changed

6 files changed

+34
-36
lines changed

src/apitypes/rest/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import { OpenAPIV3 } from 'openapi-types'
1919
import { buildRestDocument, createRestExportDocument, dumpRestDocument } from './rest.document'
2020
import { REST_API_TYPE, REST_DOCUMENT_TYPE } from './rest.consts'
2121
import { compareRestOperationsData } from './rest.changes'
22-
import { buildRestOperations, createNormalizedOperationId } from './rest.operations'
22+
import { buildRestOperations } from './rest.operations'
2323
import { parseRestFile } from './rest.parser'
24-
2524
import { ApiBuilder } from '../../types'
25+
import { createNormalizedOperationId } from '../../utils'
2626

2727
export * from './rest.consts'
2828

src/apitypes/rest/rest.operation.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
} from '../../types'
3232
import {
3333
buildSearchScope,
34+
calculateOperationId,
3435
capitalize,
3536
copySymbolIfDefined,
3637
getKeyValue,
@@ -41,9 +42,7 @@ import {
4142
isValidHttpMethod,
4243
normalizePath,
4344
rawToApiKind,
44-
removeFirstSlash,
4545
setValueByPath,
46-
slugify,
4746
takeIf,
4847
takeIfDefined,
4948
} from '../../utils'
@@ -362,12 +361,3 @@ export const extractCommonPathItemProperties = (
362361
...takeIfDefined({ servers: pathData?.servers }),
363362
...takeIfDefined({ parameters: pathData?.parameters }),
364363
})
365-
366-
export const calculateOperationId = (
367-
basePath: string,
368-
key: string,
369-
path: string,
370-
): string => {
371-
const operationPath = basePath + path
372-
return slugify(`${removeFirstSlash(operationPath)}-${key}`)
373-
}

src/apitypes/rest/rest.operations.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@
1616

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

19-
import { buildRestOperation, calculateOperationId } from './rest.operation'
20-
import { OperationIdNormalizer, OperationsBuilder } from '../../types'
21-
import {
22-
createBundlingErrorHandler,
23-
IGNORE_PATH_PARAM_UNIFIED_PLACEHOLDER,
24-
removeComponents,
25-
slugify,
26-
} from '../../utils'
19+
import { buildRestOperation } from './rest.operation'
20+
import { OperationsBuilder } from '../../types'
21+
import { calculateOperationId, createBundlingErrorHandler, removeComponents } from '../../utils'
2722
import { getOperationBasePath } from './rest.utils'
2823
import type * as TYPE from './rest.types'
2924
import { HASH_FLAG, INLINE_REFS_FLAG, MESSAGE_SEVERITY, NORMALIZE_OPTIONS, ORIGINS_SYMBOL } from '../../consts'
@@ -110,8 +105,3 @@ export const buildRestOperations: OperationsBuilder<OpenAPIV3.Document> = async
110105
}
111106
return operations
112107
}
113-
114-
export const createNormalizedOperationId: OperationIdNormalizer = (operation) => {
115-
const { metadata: { path, method } } = operation
116-
return slugify(`${path}-${method}`, [], IGNORE_PATH_PARAM_UNIFIED_PLACEHOLDER)
117-
}

src/consts.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
VALIDATION_RULES_SEVERITY_LEVEL_WARNING,
2828
ValidationRulesSeverity,
2929
} from './types'
30+
import { OpenAPIV3 } from 'openapi-types'
3031

3132
export const DEFAULT_BATCH_SIZE = 32
3233

@@ -169,3 +170,4 @@ export const EMPTY_CHANGE_SUMMARY_DTO = {
169170
}
170171

171172
export const CUSTOM_PARAMETER_API_AUDIENCE = 'x-api-audience'
173+
export const HTTP_METHODS_SET = new Set(Object.values(OpenAPIV3.HttpMethods) as string[])

src/strategies/document-group.strategy.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@ import {
2525
VersionDocument,
2626
} from '../types'
2727
import { REST_API_TYPE } from '../apitypes'
28-
import { EXPORT_FORMAT_TO_FILE_FORMAT, fromBase64, isValidHttpMethod, takeIfDefined, toVersionDocument } from '../utils'
28+
import {
29+
calculateOperationId,
30+
EXPORT_FORMAT_TO_FILE_FORMAT,
31+
fromBase64,
32+
isValidHttpMethod,
33+
takeIfDefined,
34+
toVersionDocument,
35+
} from '../utils'
2936
import { OpenAPIV3 } from 'openapi-types'
3037
import { getOperationBasePath } from '../apitypes/rest/rest.utils'
3138
import { VersionRestDocument } from '../apitypes/rest/rest.types'
3239
import { FILE_FORMAT_JSON, INLINE_REFS_FLAG, NORMALIZE_OPTIONS } from '../consts'
3340
import { normalize } from '@netcracker/qubership-apihub-api-unifier'
34-
import {
35-
calculateOperationId,
36-
calculateSpecRefs,
37-
extractCommonPathItemProperties,
38-
} from '../apitypes/rest/rest.operation'
41+
import { calculateSpecRefs, extractCommonPathItemProperties } from '../apitypes/rest/rest.operation'
3942

4043
function getTransformedDocument(document: ResolvedGroupDocument, format: FileFormat, packages: ResolvedReferenceMap): VersionRestDocument {
4144
const versionDocument = toVersionDocument(document, format)

src/utils/operations.utils.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { ApiOperation, BuildResult } from '../types'
17+
import { ApiOperation, BuildResult, OperationIdNormalizer } from '../types'
1818
import { GraphApiComponents, GraphApiDirectiveDefinition } from '@netcracker/qubership-apihub-graphapi'
1919
import { OpenAPIV3 } from 'openapi-types'
2020
import { isObject } from './objects'
21-
import { slugify } from './document'
21+
import { IGNORE_PATH_PARAM_UNIFIED_PLACEHOLDER, slugify } from './document'
2222
import { removeFirstSlash } from './builder'
2323
import { Diff, DiffAction } from '@netcracker/qubership-apihub-api-diff'
2424
import { matchPaths, OPEN_API_PROPERTY_PATHS, PREDICATE_ANY_VALUE } from '@netcracker/qubership-apihub-api-unifier'
2525
import { DirectiveLocation } from 'graphql/language'
26+
import { HTTP_METHODS_SET } from '../consts'
2627

2728
export function getOperationsList(buildResult: BuildResult): ApiOperation[] {
2829
return [...buildResult.operations.values()]
@@ -83,8 +84,20 @@ export function isOperationRemove(operationDiff: Diff): boolean {
8384
return operationDiff.action === DiffAction.remove && !!matchPaths(operationDiff.beforeDeclarationPaths, [[OPEN_API_PROPERTY_PATHS, PREDICATE_ANY_VALUE]])
8485
}
8586

86-
const HTTP_METHODS_SET = new Set(Object.values(OpenAPIV3.HttpMethods) as string[])
87-
8887
export const isValidHttpMethod = (method: string): method is OpenAPIV3.HttpMethods => {
8988
return HTTP_METHODS_SET.has(method)
9089
}
90+
91+
export const createNormalizedOperationId: OperationIdNormalizer = (operation) => {
92+
const { metadata: { path, method } } = operation
93+
return slugify(`${path}-${method}`, [], IGNORE_PATH_PARAM_UNIFIED_PLACEHOLDER)
94+
}
95+
96+
export const calculateOperationId = (
97+
basePath: string,
98+
key: string,
99+
path: string,
100+
): string => {
101+
const operationPath = basePath + path
102+
return slugify(`${removeFirstSlash(operationPath)}-${key}`)
103+
}

0 commit comments

Comments
 (0)