Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FE: fixed usage of wrong definition because of the same name #158

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions forward_engineering/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,21 @@ const { SCRIPT_TYPES, SCHEMA_REGISTRIES_KEYS } = require('../shared/constants');
const { parseJson, prepareName } = require('./helpers/generalHelper');
const validateAvroScript = require('./helpers/validateAvroScript');
const { formatAvroSchemaByType, getConfluentSubjectName } = require('./helpers/formatAvroSchemaByType');
const { resolveUdt, addDefinitions, resetDefinitionsUsage, convertCollectionReferences, resolveNamespaceReferences } = require('./helpers/udtHelper');
const {
resolveUdt,
addDefinitions,
resetDefinitionsUsage,
convertCollectionReferences,
resolveNamespaceReferences,
clearDefinitions,
} = require('./helpers/udtHelper');
const convertSchema = require('./helpers/convertJsonSchemaToAvro');
const { initPluginConfiguration, getCustomProperties, getEntityLevelConfig, getFieldLevelConfig } = require('../shared/customProperties');
const {
initPluginConfiguration,
getCustomProperties,
getEntityLevelConfig,
getFieldLevelConfig,
} = require('../shared/customProperties');
let _;

const generateModelScript = (data, logger, cb, app) => {
Expand All @@ -23,8 +35,8 @@ const generateModelScript = (data, logger, cb, app) => {
const scriptType = getScriptType(data, modelData) || SCRIPT_TYPES.CONFLUENT_SCHEMA_REGISTRY;
const needMinify = isMinifyNeeded(options);

setUserDefinedTypes(externalDefinitions);
setUserDefinedTypes(modelDefinitions);
const convertedExternalDefinitions = convertSchemaToUserDefinedTypes(externalDefinitions)
const convertedModelDefinitions = convertSchemaToUserDefinedTypes(modelDefinitions)

const entities = (containers || [])
.flatMap(container => container.entities
Expand All @@ -40,6 +52,10 @@ const generateModelScript = (data, logger, cb, app) => {
internalDefinitions,
references,
} = entity;

clearDefinitions();
addDefinitions(convertedExternalDefinitions);
addDefinitions(convertedModelDefinitions);
setUserDefinedTypes(internalDefinitions);
resetDefinitionsUsage();

Expand Down
5 changes: 5 additions & 0 deletions forward_engineering/helpers/udtHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ const addDefinitions = definitions => {
udt = { ...udt, ...definitions };
};

const clearDefinitions = () => {
udt = {};
}

const resetDefinitionsUsage = () => {
_ = dependencies.lodash;

Expand Down Expand Up @@ -343,6 +347,7 @@ module.exports = {
resolveUdt,
getUdtItem,
addDefinitions,
clearDefinitions,
convertSchemaToReference,
resetDefinitionsUsage,
convertCollectionReferences,
Expand Down