Skip to content

Commit

Permalink
fix(api,dashboard): Correct variable generation and parsing (#7324)
Browse files Browse the repository at this point in the history
  • Loading branch information
desiprisg authored Dec 18, 2024
1 parent dfe2cdc commit 72c992c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ export class BuildPayloadSchema {
const controlValues = await this.buildControlValues(command);

if (!controlValues.length) {
return {};
return {
type: 'object',
properties: {},
additionalProperties: true,
};
}

const templateVars = this.extractTemplateVariables(controlValues);
if (templateVars.length === 0) {
return {};
return {
type: 'object',
properties: {},
additionalProperties: true,
};
}

const variablesExample = pathsToObject(templateVars, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export class BuildAvailableVariableSchemaUsecase {
format: 'date-time',
description: 'The last time the subscriber was online (optional)',
},
data: {
type: 'object',
properties: {},
description: 'Additional data about the subscriber',
additionalProperties: true,
},
},
required: ['firstName', 'lastName', 'email', 'subscriberId'],
additionalProperties: false,
Expand All @@ -56,7 +62,13 @@ export class BuildAvailableVariableSchemaUsecase {
command: BuildAvailableVariableSchemaCommand
): Promise<JSONSchemaDto> {
if (workflow.payloadSchema) {
return parsePayloadSchema(workflow.payloadSchema, { safe: true }) || {};
return (
parsePayloadSchema(workflow.payloadSchema, { safe: true }) || {
type: 'object',
properties: {},
additionalProperties: true,
}
);
}

return this.buildPayloadSchema.execute(
Expand Down
12 changes: 7 additions & 5 deletions apps/dashboard/src/utils/parseStepVariablesToLiquidVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ export function parseStepVariablesToLiquidVariables(schema: JSONSchemaDefinition
for (const [key, value] of Object.entries(obj.properties)) {
const fullPath = path ? `${path}.${key}` : key;

// Add each property as a variable for autocompletion
variables.push({
type: 'variable',
label: `${fullPath}`,
});
// Only push variables that are not of type "object" or have additionalProperties set to true
if (typeof value === 'object' && (value.type !== 'object' || value.additionalProperties === true)) {
variables.push({
type: 'variable',
label: `${fullPath}`,
});
}

// Recursively process nested objects
if (typeof value === 'object' && (value.type === 'object' || value.type === 'array')) {
Expand Down

0 comments on commit 72c992c

Please sign in to comment.