Skip to content

Commit

Permalink
Merge pull request #133 from hackolade/HCK-3954--hackolade-assignment…
Browse files Browse the repository at this point in the history
…-fw-hackolade-issues

FE: fix issue with recursive collection references
  • Loading branch information
VitaliiBedletskyi authored Sep 8, 2023
2 parents a6b1eb4 + 00c6d8a commit ef37c4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions forward_engineering/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ const convertJsonToAvro = (jsonSchema, schemaName) => {
const customProperties = getCustomProperties(getEntityLevelConfig(), jsonSchema);
const schema = convertSchema(jsonSchema);
const avroSchema = {
...(_.isString(schema) ? { type: schema } : schema),
...(!_.isString(schema) && schema),
name: schemaName,
type: 'record',
type: (_.isString(schema) ? schema : 'record'),
...customProperties,
};

Expand Down
17 changes: 11 additions & 6 deletions forward_engineering/helpers/udtHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const convertCollectionReferences = entities => {
}

const definition = entities.find(entity => entity.jsonSchema.GUID === field.ref).jsonSchema;
const definitionName = definition.code || definition.collectionName;
const definitionName = definition.code || definition.collectionName || definition.name;

const subject = getConfluentSubjectName({
name: definitionName,
Expand All @@ -217,7 +217,7 @@ const convertCollectionReferences = entities => {

return {
...field,
$ref: `#/definitions/${definition.code || definition.collectionName}`,
$ref: `#/definitions/${definitionName}`,
default: field.nullable ? null : field.default,
};
});
Expand All @@ -235,20 +235,25 @@ const convertCollectionReferences = entities => {
return {
...entity,
jsonSchema,
references: filterReferencesByPath(references).map(reference => _.omit(reference, 'path')),
references: filterReferencesByPath(entity, references).map(reference => _.omit(reference, 'path')),
};
});

return topologicalSort(entitiesWithReferences);
};

const filterReferencesByPath = references => references.filter(currentReference => {
const filterReferencesByPath = (entity, references) => references.filter(currentReference => {
const isRecursive = _.last(currentReference.path) === entity?.jsonSchema?.GUID;
if (isRecursive) {
return false;
}

const rootReference = references.find(reference => {
if (!reference.path || (reference.path.length >= currentReference.path.length)) {
if (!reference.path || (reference.path.length >= currentReference.path?.length)) {
return false;
}

return reference.path.every((path, index) => path === currentReference.path[index]);
return reference.path.every((path, index) => path === currentReference.path?.[index]);
});

return !rootReference;
Expand Down

0 comments on commit ef37c4f

Please sign in to comment.