@sap-ux/annotation-converter
Advanced tools
Comparing version 0.6.13 to 0.6.14
# @sap-ux/annotation-converter | ||
## 0.6.14 | ||
### Patch Changes | ||
- 1fc2286: The annotation converter now ensures that references (aliases and namespaces) are unique | ||
## 0.6.13 | ||
@@ -4,0 +10,0 @@ |
@@ -1018,2 +1018,27 @@ "use strict"; | ||
} | ||
function getReferences(converter, rawMetadataReferences) { | ||
if (rawMetadataReferences.length === 0) { | ||
return VocabularyReferences_1.VocabularyReferences; | ||
} | ||
const references = []; | ||
const duplicates = new Set(); | ||
const collides = (a, b) => a.namespace === b.namespace || a.alias === b.alias; | ||
// process the raw references, making sure they are unique (first one wins) | ||
for (const reference of rawMetadataReferences) { | ||
const collisions = references.filter((existingReference) => collides(existingReference, reference)); | ||
if (collisions.length > 0) { | ||
collisions.forEach((reference) => duplicates.add(reference)); | ||
duplicates.add(reference); | ||
} | ||
else { | ||
references.push(reference); | ||
} | ||
} | ||
// add default vocabulary references (if not there already). Do not report conflicts as errors. | ||
references.push(...VocabularyReferences_1.VocabularyReferences.filter((reference) => references.every((existingReference) => !collides(existingReference, reference)))); | ||
if (duplicates.size > 0) { | ||
converter.logError(`The following references are not unique. Check if they are imported multiple times.\n${JSON.stringify(Array.from(duplicates), null, 2)}`); | ||
} | ||
return references; | ||
} | ||
/** | ||
@@ -1031,11 +1056,7 @@ * Convert a RawMetadata into an object representation to be used to easily navigate a metadata object and its annotation. | ||
annotations: rawMetadata.schema.annotations, | ||
references: VocabularyReferences_1.VocabularyReferences.concat(rawMetadata.references), | ||
diagnostics: [] | ||
}; | ||
// fall back on the default references if the caller does not specify any | ||
if (rawMetadata.references.length === 0) { | ||
rawMetadata.references = VocabularyReferences_1.VocabularyReferences; | ||
} | ||
// Converter | ||
const converter = new Converter(rawMetadata, convertedOutput); | ||
(0, utils_1.lazy)(convertedOutput, 'references', () => getReferences(converter, rawMetadata.references)); | ||
(0, utils_1.lazy)(convertedOutput, 'entityContainer', converter.convert(converter.rawSchema.entityContainer, convertEntityContainer)); | ||
@@ -1042,0 +1063,0 @@ (0, utils_1.lazy)(convertedOutput, 'entitySets', converter.convert(converter.rawSchema.entitySets, convertEntitySet)); |
{ | ||
"name": "@sap-ux/annotation-converter", | ||
"version": "0.6.13", | ||
"version": "0.6.14", | ||
"description": "SAP Fiori OData - Annotation converter", | ||
@@ -20,3 +20,3 @@ "repository": { | ||
"devDependencies": { | ||
"@sap-ux/edmx-parser": "0.5.14" | ||
"@sap-ux/edmx-parser": "0.5.15" | ||
}, | ||
@@ -23,0 +23,0 @@ "scripts": { |
@@ -36,2 +36,3 @@ import type { | ||
RawV4NavigationProperty, | ||
Reference, | ||
RemoveAnnotationAndType, | ||
@@ -1545,2 +1546,44 @@ ResolutionTarget, | ||
function getReferences(converter: Converter, rawMetadataReferences: Reference[]) { | ||
if (rawMetadataReferences.length === 0) { | ||
return VocabularyReferences; | ||
} | ||
const references: Reference[] = []; | ||
const duplicates = new Set<Reference>(); | ||
const collides = (a: Reference, b: Reference) => a.namespace === b.namespace || a.alias === b.alias; | ||
// process the raw references, making sure they are unique (first one wins) | ||
for (const reference of rawMetadataReferences) { | ||
const collisions = references.filter((existingReference) => collides(existingReference, reference)); | ||
if (collisions.length > 0) { | ||
collisions.forEach((reference) => duplicates.add(reference)); | ||
duplicates.add(reference); | ||
} else { | ||
references.push(reference); | ||
} | ||
} | ||
// add default vocabulary references (if not there already). Do not report conflicts as errors. | ||
references.push( | ||
...VocabularyReferences.filter((reference) => | ||
references.every((existingReference) => !collides(existingReference, reference)) | ||
) | ||
); | ||
if (duplicates.size > 0) { | ||
converter.logError( | ||
`The following references are not unique. Check if they are imported multiple times.\n${JSON.stringify( | ||
Array.from(duplicates), | ||
null, | ||
2 | ||
)}` | ||
); | ||
} | ||
return references; | ||
} | ||
/** | ||
@@ -1558,14 +1601,10 @@ * Convert a RawMetadata into an object representation to be used to easily navigate a metadata object and its annotation. | ||
annotations: rawMetadata.schema.annotations, | ||
references: VocabularyReferences.concat(rawMetadata.references), | ||
diagnostics: [] | ||
} as any; | ||
// fall back on the default references if the caller does not specify any | ||
if (rawMetadata.references.length === 0) { | ||
rawMetadata.references = VocabularyReferences; | ||
} | ||
// Converter | ||
const converter = new Converter(rawMetadata, convertedOutput); | ||
lazy(convertedOutput, 'references', () => getReferences(converter, rawMetadata.references)); | ||
lazy( | ||
@@ -1572,0 +1611,0 @@ convertedOutput, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
224681
3686