|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -import { ApiOperation, BuildResult } from '../types' |
| 17 | +import { ApiOperation, BuildResult, OperationIdNormalizer } from '../types' |
18 | 18 | import { GraphApiComponents, GraphApiDirectiveDefinition } from '@netcracker/qubership-apihub-graphapi' |
19 | 19 | import { OpenAPIV3 } from 'openapi-types' |
20 | 20 | import { isObject } from './objects' |
21 | | -import { slugify } from './document' |
| 21 | +import { IGNORE_PATH_PARAM_UNIFIED_PLACEHOLDER, slugify } from './document' |
22 | 22 | import { removeFirstSlash } from './builder' |
23 | 23 | import { Diff, DiffAction } from '@netcracker/qubership-apihub-api-diff' |
24 | 24 | import { matchPaths, OPEN_API_PROPERTY_PATHS, PREDICATE_ANY_VALUE } from '@netcracker/qubership-apihub-api-unifier' |
25 | 25 | import { DirectiveLocation } from 'graphql/language' |
| 26 | +import { HTTP_METHODS_SET } from '../consts' |
26 | 27 |
|
27 | 28 | export function getOperationsList(buildResult: BuildResult): ApiOperation[] { |
28 | 29 | return [...buildResult.operations.values()] |
@@ -83,8 +84,20 @@ export function isOperationRemove(operationDiff: Diff): boolean { |
83 | 84 | return operationDiff.action === DiffAction.remove && !!matchPaths(operationDiff.beforeDeclarationPaths, [[OPEN_API_PROPERTY_PATHS, PREDICATE_ANY_VALUE]]) |
84 | 85 | } |
85 | 86 |
|
86 | | -const HTTP_METHODS_SET = new Set(Object.values(OpenAPIV3.HttpMethods) as string[]) |
87 | | - |
88 | 87 | export const isValidHttpMethod = (method: string): method is OpenAPIV3.HttpMethods => { |
89 | 88 | return HTTP_METHODS_SET.has(method) |
90 | 89 | } |
| 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