parent 31afee7de8
author zcason <a-zcason@expediagroup.com> 1672698922 -0600 committer blam <ben@blam.sh> 1677246287 +0100 added zod-to-json-schema package Signed-off-by: zcason <a-zcason@expediagroup.com> updated input types Signed-off-by: zcason <a-zcason@expediagroup.com> updated the conversion function to return an object Signed-off-by: zcason <a-zcason@expediagroup.com> zod converter function refactor Signed-off-by: zcason <a-zcason@expediagroup.com> added changeset Signed-off-by: zcason <a-zcason@expediagroup.com> zod to json package update Signed-off-by: zcason <a-zcason@expediagroup.com> zod to json package update Signed-off-by: zcason <a-zcason@expediagroup.com> removed comments Signed-off-by: zcason <a-zcason@expediagroup.com> Signed-off-by: zcason <a-zcason@expediagroup.com> Signed-off-by: zcason <a-zcason@expediagroup.com> empty commit Signed-off-by: zcason <a-zcason@expediagroup.com> moved zod converter into its own file Signed-off-by: zcason <a-zcason@expediagroup.com> moved zod converter into its own file Signed-off-by: zcason <a-zcason@expediagroup.com> updated report Signed-off-by: zcason <a-zcason@expediagroup.com> added public tag Signed-off-by: zcason <a-zcason@expediagroup.com> added public tag to exported function Signed-off-by: zcason <a-zcason@expediagroup.com> updated changeset Signed-off-by: zcason <a-zcason@expediagroup.com> removed zod to json module from global package Signed-off-by: zcason <a-zcason@expediagroup.com> update zod to json module from scaffolder package.json Signed-off-by: zcason <a-zcason@expediagroup.com> update zod to json module from scaffolder package.json Signed-off-by: zcason <a-zcason@expediagroup.com> reverted zod to json module from scaffolder package.json Signed-off-by: zcason <a-zcason@expediagroup.com> moved zod to json converter function into a new directory Signed-off-by: zcason <a-zcason@expediagroup.com> refactored zod coverion function Signed-off-by: zcason <a-zcason@expediagroup.com> updated changeset description Signed-off-by: zcason <a-zcason@expediagroup.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend': minor
|
||||
---
|
||||
|
||||
zod to json conversion funcitonality for action template schema
|
||||
@@ -69,8 +69,10 @@ export function createCatalogRegisterAction(options: {
|
||||
}
|
||||
>;
|
||||
|
||||
// @public
|
||||
export function createCatalogWriteAction(): TemplateAction_2<{
|
||||
// Warning: (ae-missing-release-tag) "createCatalogWriteAction" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
export function createCatalogWriteAction(): TemplateAction<{
|
||||
filePath?: string | undefined;
|
||||
entity: Entity;
|
||||
}>;
|
||||
|
||||
@@ -92,7 +92,8 @@
|
||||
"winston": "^3.2.1",
|
||||
"yaml": "^2.0.0",
|
||||
"zen-observable": "^0.10.0",
|
||||
"zod": "~3.18.0"
|
||||
"zod": "~3.18.0",
|
||||
"zod-to-json-schema": "~3.18.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
|
||||
@@ -19,6 +19,8 @@ import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import * as yaml from 'yaml';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { resolveSafeChildPath } from '@backstage/backend-common';
|
||||
import { z } from 'zod';
|
||||
import { convertZodtoJson } from '../../../tasks';
|
||||
|
||||
const id = 'catalog:write';
|
||||
|
||||
@@ -56,28 +58,24 @@ const examples = [
|
||||
* Writes a catalog descriptor file containing the provided entity to a path in the workspace.
|
||||
* @public
|
||||
*/
|
||||
|
||||
export function createCatalogWriteAction() {
|
||||
const inputSchema = convertZodtoJson(
|
||||
z.object({
|
||||
filePath: z.string().optional().describe('Defaults to catalog-info.yaml'),
|
||||
entity: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('You can provide the same values used in the Entity schema.'),
|
||||
}),
|
||||
);
|
||||
|
||||
return createTemplateAction<{ filePath?: string; entity: Entity }>({
|
||||
id,
|
||||
description: 'Writes the catalog-info.yaml for your template',
|
||||
examples,
|
||||
schema: {
|
||||
input: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
filePath: {
|
||||
title: 'Catalog file path',
|
||||
description: 'Defaults to catalog-info.yaml',
|
||||
type: 'string',
|
||||
},
|
||||
entity: {
|
||||
title: 'Entity info to write catalog-info.yaml',
|
||||
description:
|
||||
'You can provide the same values used in the Entity schema.',
|
||||
type: 'object',
|
||||
},
|
||||
},
|
||||
},
|
||||
input: inputSchema,
|
||||
},
|
||||
supportsDryRun: true,
|
||||
async handler(ctx) {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2023 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { z } from 'zod';
|
||||
import zodToJsonSchema from 'zod-to-json-schema';
|
||||
import { Schema } from 'jsonschema';
|
||||
|
||||
interface TemplateActionSchema {
|
||||
readonly schema: {
|
||||
input?: Schema;
|
||||
output?: Schema;
|
||||
};
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export function convertZodtoJson<
|
||||
TInputSchema extends z.ZodType = z.ZodType<any, any, {}>,
|
||||
TOutputSchema extends z.ZodType = z.ZodType<any, any, {}>,
|
||||
>(
|
||||
zodInputSchema?: TInputSchema,
|
||||
zodOutputSchema?: TOutputSchema,
|
||||
): TemplateActionSchema {
|
||||
return {
|
||||
schema: {
|
||||
input: zodInputSchema ? zodToJsonSchema(zodInputSchema) : undefined,
|
||||
output: zodOutputSchema ? zodToJsonSchema(zodOutputSchema) : undefined,
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user