diff --git a/forward_engineering/api.js b/forward_engineering/api.js index 263aa89..c6718ed 100644 --- a/forward_engineering/api.js +++ b/forward_engineering/api.js @@ -33,6 +33,8 @@ const LOGICAL_TYPES_MAP = { fixed: ['decimal', 'duration'] }; +const RecordNameStrategy = 'RecordNameStrategy'; +const TopicRecordNameStrategy = 'TopicRecordNameStrategy'; module.exports = { generateModelScript(data, logger, cb) { logger.clear(); @@ -107,8 +109,9 @@ const getCommonEntitiesData = (data) => { }, additionalOptions: data.options.additionalOptions }; + const modelData = _.get(data, 'modelData[0]', {}) - return { options, modelDefinitions, externalDefinitions } + return { options, modelDefinitions, externalDefinitions, modelData } } const getEntityData = (container, entityId) => { @@ -121,6 +124,31 @@ const getEntityData = (container, entityId) => { return { containerData, jsonSchema, jsonData, entityData, internalDefinitions } } +const getConfluentPostQuery = ({ data, schema }) => { + const getName = ()=>{ + const name = getRecordName(data); + const typePostfix = _.has(data, 'entityData.schemaType') ? `-${data.entityData.schemaType}` : ''; + const containerPrefix = _.has(data, 'containerData.name') ? `${data.containerData.name}.`:''; + const topicPrefix = _.has(data, 'modelData.schemaTopic') ? `${data.modelData.schemaTopic}-`:''; + + const schemaNameStrategy = _.get(data, 'modelData.schemaNameStrategy', ''); + switch(schemaNameStrategy){ + case RecordNameStrategy: + return `${containerPrefix}${name}${typePostfix}` + case TopicRecordNameStrategy: + return `${topicPrefix}${containerPrefix}${name}${typePostfix}` + default: + return `${name}${typePostfix}`; + } + } + + return `POST /subjects/${getName()}/versions\n${JSON.stringify( + { schema, schemaType: "AVRO" }, + null, + 4 + )}`; +}; + const getScript = (data) => { const name = getRecordName(data); let avroSchema = { name }; @@ -146,9 +174,9 @@ const getScript = (data) => { const needMinify = (additionalOptions.find(option => option.id === 'minify') || {}).value; if (targetScriptType === 'confluentSchemaRegistry') { - const schema = needMinify?JSON.stringify(avroSchema):avroSchema; + const schema = needMinify ? JSON.stringify(avroSchema) : avroSchema; - return `POST /subjects/${name}/versions\n${JSON.stringify({ schema, schemaType: "AVRO" }, null, 4)}` + return getConfluentPostQuery({ data, schema}); } if (needMinify) { diff --git a/properties_pane/defaultData.json b/properties_pane/defaultData.json index ab62bfb..1cb0be3 100644 --- a/properties_pane/defaultData.json +++ b/properties_pane/defaultData.json @@ -2,7 +2,8 @@ "model": { "modelName": "New model", "dbVersion": "", - "dbVendor": "Avro" + "dbVendor": "Avro", + "schemaNameStrategy":"TopicNameStrategy" }, "container": { "name": "New_namespace", diff --git a/properties_pane/entity_level/entityLevelConfig.json b/properties_pane/entity_level/entityLevelConfig.json index c637f6b..67d8442 100644 --- a/properties_pane/entity_level/entityLevelConfig.json +++ b/properties_pane/entity_level/entityLevelConfig.json @@ -140,6 +140,17 @@ making sure that you maintain a proper JSON format. "propertyTooltip": "Namespace", "propertyType": "selecthashed" }, + { + "propertyName": "Confluent schema type", + "propertyKeyword": "schemaType", + "propertyTooltip": "Select from list of options", + "propertyType": "select", + "options": [ + "", + "value", + "key" + ] + }, { "propertyName": "Additional properties", "propertyKeyword": "additionalProperties", diff --git a/properties_pane/model_level/modelLevelConfig.json b/properties_pane/model_level/modelLevelConfig.json index 0ab3c9b..97285d6 100644 --- a/properties_pane/model_level/modelLevelConfig.json +++ b/properties_pane/model_level/modelLevelConfig.json @@ -139,6 +139,28 @@ making sure that you maintain a proper JSON format. ], "disabledOption": true }, + { + "propertyName": "Subject Name Strategy", + "propertyKeyword": "schemaNameStrategy", + "propertyTooltip": "Select from list of options", + "propertyType": "select", + "options": [ + "TopicNameStrategy", + "RecordNameStrategy", + "TopicRecordNameStrategy" + ] + }, + { + "propertyName": "Topic", + "propertyKeyword": "schemaTopic", + "shouldValidate": false, + "propertyTooltip": "", + "propertyType": "text", + "dependency": { + "key": "schemaNameStrategy", + "value": "TopicRecordNameStrategy" + } + }, { "propertyName": "Comments", "propertyKeyword": "comments", diff --git a/reverse_engineering/api.js b/reverse_engineering/api.js index d661914..3ce1232 100644 --- a/reverse_engineering/api.js +++ b/reverse_engineering/api.js @@ -9,7 +9,7 @@ const jsonSchemaAdapter = require('./helpers/adaptJsonSchema'); const DEFAULT_FIELD_NAME = 'New_field'; let stateExtension = null; -const ADDITIONAL_PROPS = ['logicalType', 'scale', 'precision', 'name', 'arrayItemName', 'doc', 'order', 'aliases', 'symbols', 'namespace', 'size', 'default', 'pattern', 'choice']; +const ADDITIONAL_PROPS = ['schemaType', 'logicalType', 'scale', 'precision', 'name', 'arrayItemName', 'doc', 'order', 'aliases', 'symbols', 'namespace', 'size', 'default', 'pattern', 'choice']; const DATA_TYPES = [ 'string', 'bytes',