Skip to content

Commit

Permalink
fix(orchestrator): resolve mismatch between execution data and compos…
Browse files Browse the repository at this point in the history
…ed schema (#1217)

fix(orchestrator): resolve mismatch between workflow data and composed schemas
  • Loading branch information
batzionb authored Feb 16, 2024
1 parent 7ceaaf8 commit af85114
Show file tree
Hide file tree
Showing 17 changed files with 1,674 additions and 839 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import { JsonObject } from '@backstage/types';

import { JSONSchema7 } from 'json-schema';

import { WorkflowItem } from '@janus-idp/backstage-plugin-orchestrator-common';

const schema = {
$id: 'classpath:/schemas/yamlgreet__main-schema.json',
title: 'Data Input Schema',
$schema: 'http://json-schema.org/draft-07/schema#',
type: 'object',
properties: {
language: {
type: 'object',
properties: {
language: {
title: 'Language',
description: 'Language to greet',
type: 'string',
enum: ['English', 'Spanish'],
default: 'English',
},
},
title: 'Language',
},
name: {
type: 'object',
properties: {
name: {
title: 'Name',
description: 'Name of the person',
type: 'string',
default: 'John Doe',
},
},
},
},
required: ['name'],
} as JSONSchema7;

const workflowItem = {
uri: 'yamlgreet.sw.yaml',
definition: {
id: 'yamlgreet',
version: '1.0',
specVersion: '0.8',
name: 'Greeting workflow',
description: 'YAML based greeting workflow',
dataInputSchema: 'schemas/yamlgreet__main-schema.json',
start: 'ChooseOnLanguage',
functions: [
{
name: 'greetFunction',
type: 'custom',
operation: 'sysout',
},
],
states: [
{
name: 'ChooseOnLanguage',
type: 'switch',
dataConditions: [
{
condition: '${ .language.language == "English" }',
transition: 'GreetInEnglish',
},
{
condition: '${ .language.language == "Spanish" }',
transition: 'GreetInSpanish',
},
],
defaultCondition: {
transition: 'GreetInEnglish',
},
},
{
name: 'GreetInEnglish',
type: 'inject',
data: {
greeting: 'Hello from YAML Workflow, ',
},
transition: 'GreetPerson',
},
{
name: 'GreetInSpanish',
type: 'inject',
data: {
greeting: 'Saludos desde YAML Workflow, ',
},
transition: 'GreetPerson',
},
{
name: 'GreetPerson',
type: 'operation',
actions: [
{
name: 'greetAction',
functionRef: {
refName: 'greetFunction',
arguments: {
message: '.greeting+.name.name',
},
},
},
],
end: {
terminate: true,
},
},
],
},
} as WorkflowItem;

const variables = {
workflowdata: {
name: {
name: 'John Doe',
},
language: {
language: 'Spanish',
},
greeting: 'hello',
},
};

const mockData: {
schema: JSONSchema7;
workflowItem: WorkflowItem;
variables: JsonObject;
} = { schema, workflowItem, variables };

export default mockData;
117 changes: 117 additions & 0 deletions plugins/orchestrator-backend/__fixtures__/mockGreetingWorkflowData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { JsonObject } from '@backstage/types';

import { JSONSchema7 } from 'json-schema';

import { WorkflowItem } from '@janus-idp/backstage-plugin-orchestrator-common';

const schema = {
$id: 'classpath:/schemas/yamlgreet__main-schema.json',
title: 'Data Input Schema',
$schema: 'http://json-schema.org/draft-07/schema#',
type: 'object',
properties: {
language: {
title: 'Language',
description: 'Language to greet',
type: 'string',
enum: ['English', 'Spanish'],
default: 'English',
},
name: {
title: 'Name',
description: 'Name of the person',
type: 'string',
default: 'John Doe',
},
},
required: ['name'],
} as JSONSchema7;

const workflowItem = {
uri: 'yamlgreet.sw.yaml',
definition: {
id: 'yamlgreet',
version: '1.0',
specVersion: '0.8',
name: 'Greeting workflow',
description: 'YAML based greeting workflow',
dataInputSchema: 'schemas/yamlgreet__main-schema.json',
start: 'ChooseOnLanguage',
functions: [
{
name: 'greetFunction',
type: 'custom',
operation: 'sysout',
},
],
states: [
{
name: 'ChooseOnLanguage',
type: 'switch',
dataConditions: [
{
condition: '${ .language == "English" }',
transition: 'GreetInEnglish',
},
{
condition: '${ .language == "Spanish" }',
transition: 'GreetInSpanish',
},
],
defaultCondition: {
transition: 'GreetInEnglish',
},
},
{
name: 'GreetInEnglish',
type: 'inject',
data: {
greeting: 'Hello from YAML Workflow, ',
},
transition: 'GreetPerson',
},
{
name: 'GreetInSpanish',
type: 'inject',
data: {
greeting: 'Saludos desde YAML Workflow, ',
},
transition: 'GreetPerson',
},
{
name: 'GreetPerson',
type: 'operation',
actions: [
{
name: 'greetAction',
functionRef: {
refName: 'greetFunction',
arguments: {
message: '.greeting+.name',
},
},
},
],
end: {
terminate: true,
},
},
],
},
} as WorkflowItem;

const variables = {
workflowdata: {
name: 'John Doe',
greeting: 'Saludos desde YAML Workflow, ',
language: 'Spanish',
},
};

const mockData: {
schema: JSONSchema7;
workflowItem: WorkflowItem;
variables: JsonObject;
} = { schema, workflowItem, variables };

export default mockData;
Loading

0 comments on commit af85114

Please sign in to comment.