chore: implemented zod parsing in test

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2023-02-23 12:07:04 +01:00
parent 10a64ff693
commit 1bbd6dfe67
2 changed files with 9 additions and 5 deletions
@@ -175,7 +175,7 @@ describe('DefaultWorkflowRunner', () => {
});
await expect(runner.execute(task)).rejects.toThrow(
/Invalid input passed to action jest-validated-action, instance requires property \"foo\"/,
/Invalid input passed to action jest-zod-validated-action, instance requires property \"foo\"/,
);
});
@@ -25,6 +25,7 @@ import { InputError } from '@backstage/errors';
import { PassThrough } from 'stream';
import { generateExampleOutput, isTruthy } from './helper';
import { validate as validateJsonSchema } from 'jsonschema';
import zodToJsonSchema from 'zod-to-json-schema';
import { parseRepoUrl } from '../actions/builtin/publish/util';
import { TemplateActionRegistry } from '../actions';
import {
@@ -41,6 +42,7 @@ import {
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
import { UserEntity } from '@backstage/catalog-model';
import { createCounterMetric, createHistogramMetric } from '../../util/metrics';
import { z } from 'zod';
type NunjucksWorkflowRunnerOptions = {
workingDirectory: string;
@@ -286,10 +288,12 @@ export class NunjucksWorkflowRunner implements WorkflowRunner {
{};
if (action.schema?.input) {
const validateResult = validateJsonSchema(
input,
action.schema.input,
);
const inputSchema =
action.schema.input instanceof z.ZodSchema
? zodToJsonSchema(action.schema.input)
: action.schema.input;
const validateResult = validateJsonSchema(input, inputSchema);
if (!validateResult.valid) {
const errors = validateResult.errors.join(', ');
throw new InputError(