chore: use the original schema type intead
Signed-off-by: benjdlambert <ben@blam.sh>
This commit is contained in:
@@ -97,7 +97,7 @@
|
||||
"globby": "^11.0.0",
|
||||
"isbinaryfile": "^5.0.0",
|
||||
"isolated-vm": "^5.0.1",
|
||||
"json-schema": "^0.4.0",
|
||||
"jsonschema": "^1.5.0",
|
||||
"knex": "^3.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"logform": "^2.3.2",
|
||||
|
||||
@@ -18,7 +18,7 @@ import { Config, readDurationFromConfig } from '@backstage/config';
|
||||
import { HumanDuration } from '@backstage/types';
|
||||
|
||||
import { isArray } from 'lodash';
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
import { Schema } from 'jsonschema';
|
||||
|
||||
/**
|
||||
* Returns true if the input is not `false`, `undefined`, `null`, `""`, `0`, or
|
||||
@@ -29,7 +29,7 @@ export function isTruthy(value: any): boolean {
|
||||
return isArray(value) ? value.length > 0 : !!value;
|
||||
}
|
||||
|
||||
export function generateExampleOutput(schema: JSONSchema7): unknown {
|
||||
export function generateExampleOutput(schema: Schema): unknown {
|
||||
const { examples } = schema as { examples?: unknown };
|
||||
if (examples && Array.isArray(examples)) {
|
||||
return examples[0];
|
||||
@@ -38,13 +38,13 @@ export function generateExampleOutput(schema: JSONSchema7): unknown {
|
||||
return Object.fromEntries(
|
||||
Object.entries(schema.properties ?? {}).map(([key, value]) => [
|
||||
key,
|
||||
generateExampleOutput(value as JSONSchema7),
|
||||
generateExampleOutput(value as Schema),
|
||||
]),
|
||||
);
|
||||
} else if (schema.type === 'array') {
|
||||
const [firstSchema] = [schema.items]?.flat();
|
||||
if (firstSchema) {
|
||||
return [generateExampleOutput(firstSchema as JSONSchema7)];
|
||||
return [generateExampleOutput(firstSchema as Schema)];
|
||||
}
|
||||
return [];
|
||||
} else if (schema.type === 'string') {
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
"fs-extra": "^11.2.0",
|
||||
"globby": "^11.0.0",
|
||||
"isomorphic-git": "^1.23.0",
|
||||
"json-schema": "^0.4.0",
|
||||
"jsonschema": "^1.5.0",
|
||||
"p-limit": "^3.1.0",
|
||||
"tar": "^6.1.12",
|
||||
"winston": "^3.2.1",
|
||||
|
||||
@@ -20,7 +20,7 @@ import { JsonObject, JsonValue } from '@backstage/types';
|
||||
import { TaskSecrets } from '../tasks';
|
||||
import { TemplateInfo } from '@backstage/plugin-scaffolder-common';
|
||||
import { UserEntity } from '@backstage/catalog-model';
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
import { Schema } from 'jsonschema';
|
||||
import {
|
||||
BackstageCredentials,
|
||||
LoggerService,
|
||||
@@ -175,8 +175,8 @@ export type TemplateAction<
|
||||
examples?: { description: string; example: string }[];
|
||||
supportsDryRun?: boolean;
|
||||
schema?: {
|
||||
input?: JSONSchema7;
|
||||
output?: JSONSchema7;
|
||||
input?: Schema;
|
||||
output?: Schema;
|
||||
};
|
||||
handler: (
|
||||
ctx: ActionContext<TActionInput, TActionOutput, TSchemaType>,
|
||||
|
||||
@@ -21,7 +21,7 @@ import { ScmIntegrationRegistry } from '@backstage/integration';
|
||||
import { TemplateActionOptions } from './createTemplateAction';
|
||||
import zodToJsonSchema from 'zod-to-json-schema';
|
||||
import { z } from 'zod';
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
import { Schema } from 'jsonschema';
|
||||
|
||||
/**
|
||||
* @public
|
||||
@@ -145,16 +145,16 @@ const isNativeZodSchema = (
|
||||
|
||||
export const parseSchemas = (
|
||||
action: TemplateActionOptions,
|
||||
): { inputSchema?: JSONSchema7; outputSchema?: JSONSchema7 } => {
|
||||
): { inputSchema?: Schema; outputSchema?: Schema } => {
|
||||
if (!action.schema) {
|
||||
return { inputSchema: undefined, outputSchema: undefined };
|
||||
}
|
||||
|
||||
if (isZodSchema(action.schema.input)) {
|
||||
return {
|
||||
inputSchema: zodToJsonSchema(action.schema.input) as JSONSchema7,
|
||||
inputSchema: zodToJsonSchema(action.schema.input) as Schema,
|
||||
outputSchema: isZodSchema(action.schema.output)
|
||||
? (zodToJsonSchema(action.schema.output) as JSONSchema7)
|
||||
? (zodToJsonSchema(action.schema.output) as Schema)
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
@@ -167,7 +167,7 @@ export const parseSchemas = (
|
||||
);
|
||||
|
||||
return {
|
||||
inputSchema: zodToJsonSchema(input) as JSONSchema7,
|
||||
inputSchema: zodToJsonSchema(input) as Schema,
|
||||
outputSchema: isNativeZodSchema(action.schema.output)
|
||||
? (zodToJsonSchema(
|
||||
z.object(
|
||||
@@ -175,7 +175,7 @@ export const parseSchemas = (
|
||||
Object.entries(action.schema.output).map(([k, v]) => [k, v(z)]),
|
||||
),
|
||||
),
|
||||
) as JSONSchema7)
|
||||
) as Schema)
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7716,7 +7716,7 @@ __metadata:
|
||||
globby: ^11.0.0
|
||||
isbinaryfile: ^5.0.0
|
||||
isolated-vm: ^5.0.1
|
||||
json-schema: ^0.4.0
|
||||
jsonschema: ^1.5.0
|
||||
knex: ^3.0.0
|
||||
lodash: ^4.17.21
|
||||
logform: ^2.3.2
|
||||
@@ -7794,7 +7794,7 @@ __metadata:
|
||||
fs-extra: ^11.2.0
|
||||
globby: ^11.0.0
|
||||
isomorphic-git: ^1.23.0
|
||||
json-schema: ^0.4.0
|
||||
jsonschema: ^1.5.0
|
||||
p-limit: ^3.1.0
|
||||
tar: ^6.1.12
|
||||
winston: ^3.2.1
|
||||
@@ -34244,10 +34244,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"jsonschema@npm:^1.2.6":
|
||||
version: 1.4.1
|
||||
resolution: "jsonschema@npm:1.4.1"
|
||||
checksum: 1ef02a6cd9bc32241ec86bbf1300bdbc3b5f2d8df6eb795517cf7d1cd9909e7beba1e54fdf73990fd66be98a182bda9add9607296b0cb00b1348212988e424b2
|
||||
"jsonschema@npm:^1.2.6, jsonschema@npm:^1.5.0":
|
||||
version: 1.5.0
|
||||
resolution: "jsonschema@npm:1.5.0"
|
||||
checksum: 170b9c375967bc135f4d029fedc31f5686f2c3bb07e7472cebddbb907b5369bf75a1a50287d6af9c31f61c76fe0b7786e78044c188aaddd329b77d856475e6db
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Reference in New Issue
Block a user