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

fix(api,dashboard): Correct variable generation and parsing #7324

Merged
merged 1 commit into from
Dec 18, 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
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
Loading