catalog-model: make Template beta2 step id and name optional

This commit is contained in:
Patrik Oldsberg
2021-02-23 23:53:23 +01:00
parent 1719d05cbc
commit 7c3f65f3b2
4 changed files with 23 additions and 4 deletions
@@ -106,4 +106,19 @@ describe('templateEntityV1beta2Validator', () => {
delete (entity as any).spec.steps;
await expect(validator.check(entity)).rejects.toThrow(/steps/);
});
it('accepts step with missing id', async () => {
delete (entity as any).spec.steps[0].id;
await expect(validator.check(entity)).resolves.toBe(true);
});
it('accepts step with missing name', async () => {
delete (entity as any).spec.steps[0].name;
await expect(validator.check(entity)).resolves.toBe(true);
});
it('rejects step with missing action', async () => {
delete (entity as any).spec.steps[0].action;
await expect(validator.check(entity)).rejects.toThrow(/action/);
});
});
@@ -35,8 +35,8 @@ export interface TemplateEntityV1beta2 extends Entity {
type: string;
parameters?: JsonObject | JsonObject[];
steps: Array<{
id: string;
name: string;
id?: string;
name?: string;
action: string;
parameters?: JsonObject;
}>;
@@ -111,7 +111,7 @@
"items": {
"type": "object",
"description": "A description of the step to execute.",
"required": ["id", "name", "action"],
"required": ["action"],
"properties": {
"id": {
"type": "string",
@@ -360,7 +360,11 @@ export async function createRouter(
taskSpec = {
values,
steps: template.spec.steps,
steps: template.spec.steps.map((step, index) => ({
...step,
id: step.id ?? `step-${index + 1}`,
name: step.name ?? step.action,
})),
output: template.spec.output ?? {},
};
} else {