Skip to content

Commit 67ba064

Browse files
committed
Merge branch 'main' into develop
2 parents 93b7225 + a3698b6 commit 67ba064

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

.github/workflows/frontend-ci.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ on:
44
push:
55
branches:
66
- release
7+
- hotfix
78
- develop
89
- feature/*
10+
- bugfix/*
911
tags:
1012
- '**'
1113
delete:
12-
branches:
13-
- release
14-
- feature/*
1514

1615
jobs:
1716
call-frontend-ci-workflow:

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@netcracker/qubership-apihub-api-processor",
3-
"version": "3.0.5-dev.1",
3+
"version": "3.0.6",
44
"description": "",
55
"license": "Apache-2.0",
66
"module": "dist/esm/src/index.js",

src/strategies/document-group.strategy.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import { REST_API_TYPE } from '../apitypes'
2828
import {
2929
EXPORT_FORMAT_TO_FILE_FORMAT,
3030
fromBase64,
31+
getDocumentTitle,
32+
getFileExtension,
3133
removeFirstSlash,
3234
slugify,
3335
takeIfDefined,
@@ -39,6 +41,7 @@ import { VersionRestDocument } from '../apitypes/rest/rest.types'
3941
import { INLINE_REFS_FLAG, NORMALIZE_OPTIONS } from '../consts'
4042
import { normalize } from '@netcracker/qubership-apihub-api-unifier'
4143
import { calculateSpecRefs, extractCommonPathItemProperties } from '../apitypes/rest/rest.operation'
44+
import { groupBy } from 'graphql/jsutils/groupBy'
4245

4346
async function getTransformedDocument(document: ResolvedDocument, format: FileFormat): Promise<VersionRestDocument> {
4447
const versionDocument = toVersionDocument(document, format)
@@ -94,15 +97,36 @@ export class DocumentGroupStrategy implements BuilderStrategy {
9497
}
9598

9699
const transformedDocuments = await Promise.all(transformTasks)
100+
const transformedDocumentsWithoutCollisions = (['fileId', 'filename'] as const).reduce(resolveCollisionsByField, transformedDocuments)
97101

98-
for (const transformedDocument of transformedDocuments) {
99-
buildResult.documents.set(transformedDocument.fileId, transformedDocument)
102+
for (const document of transformedDocumentsWithoutCollisions) {
103+
buildResult.documents.set(document.fileId, document)
100104
}
101105

102106
return buildResult
103107
}
104108
}
105109

110+
// there is a chance that the renamed document will be the same as another document (this case has not been fixed yet)
111+
function resolveCollisionsByField(docs: VersionRestDocument[], field: 'fileId' | 'filename'): VersionRestDocument[] {
112+
const fileIdMap = groupBy(docs, (document) => document[field])
113+
return ([...fileIdMap.values()] as VersionRestDocument[][]).reduce((acc, docs) => {
114+
const [_, ...duplicates] = docs
115+
duplicates.forEach((document, index) => {document[field] = renameDuplicate(document[field], index)})
116+
return [...acc, ...docs]
117+
}, [] as VersionRestDocument[])
118+
}
119+
120+
function renameDuplicate(fileName: string, index: number): string {
121+
const extension = getFileExtension(fileName)
122+
const nameWithPostfix = `${getDocumentTitle(fileName)}-${index + 1}`
123+
124+
if (extension) {
125+
return `${nameWithPostfix}.${extension}`
126+
}
127+
return nameWithPostfix
128+
}
129+
106130
function parseBase64String(value: string): object {
107131
return JSON.parse(fromBase64(value))
108132
}

0 commit comments

Comments
 (0)