refactor(scaffolder): abstract away zod schema types
Signed-off-by: Phil Kuang <pkuang@factset.com>
This commit is contained in:
@@ -35,7 +35,6 @@ import { TaskStep } from '@backstage/plugin-scaffolder-common';
|
||||
import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common';
|
||||
import { UIOptionsType } from '@rjsf/utils';
|
||||
import { UiSchema } from '@rjsf/utils';
|
||||
import { z } from 'zod';
|
||||
|
||||
// @alpha
|
||||
export function createNextScaffolderFieldExtension<
|
||||
@@ -91,33 +90,19 @@ export const EntityPickerFieldExtension: FieldExtensionComponent<
|
||||
>;
|
||||
|
||||
// @public
|
||||
export type EntityPickerUiOptions = z.infer<typeof EntityPickerUiOptionsSchema>;
|
||||
export type EntityPickerUiOptions =
|
||||
typeof EntityPickerUiOptionsSchema.schemaType;
|
||||
|
||||
// @public (undocumented)
|
||||
export const EntityPickerUiOptionsSchema: z.ZodObject<
|
||||
{
|
||||
allowedKinds: z.ZodOptional<z.ZodArray<z.ZodString, 'many'>>;
|
||||
defaultKind: z.ZodOptional<z.ZodString>;
|
||||
allowArbitraryValues: z.ZodOptional<z.ZodBoolean>;
|
||||
defaultNamespace: z.ZodOptional<
|
||||
z.ZodUnion<[z.ZodString, z.ZodLiteral<false>]>
|
||||
>;
|
||||
},
|
||||
'strip',
|
||||
z.ZodTypeAny,
|
||||
{
|
||||
export const EntityPickerUiOptionsSchema: {
|
||||
jsonSchema: JSONSchema7;
|
||||
schemaType: {
|
||||
defaultKind?: string | undefined;
|
||||
defaultNamespace?: string | false | undefined;
|
||||
allowedKinds?: string[] | undefined;
|
||||
allowArbitraryValues?: boolean | undefined;
|
||||
},
|
||||
{
|
||||
defaultKind?: string | undefined;
|
||||
defaultNamespace?: string | false | undefined;
|
||||
allowedKinds?: string[] | undefined;
|
||||
allowArbitraryValues?: boolean | undefined;
|
||||
}
|
||||
>;
|
||||
};
|
||||
};
|
||||
|
||||
// @public
|
||||
export const EntityTagsPickerFieldExtension: FieldExtensionComponent<
|
||||
@@ -130,30 +115,18 @@ export const EntityTagsPickerFieldExtension: FieldExtensionComponent<
|
||||
>;
|
||||
|
||||
// @public
|
||||
export type EntityTagsPickerUiOptions = z.infer<
|
||||
typeof EntityTagsPickerUiOptionsSchema
|
||||
>;
|
||||
export type EntityTagsPickerUiOptions =
|
||||
typeof EntityTagsPickerUiOptionsSchema.schemaType;
|
||||
|
||||
// @public (undocumented)
|
||||
export const EntityTagsPickerUiOptionsSchema: z.ZodObject<
|
||||
{
|
||||
kinds: z.ZodOptional<z.ZodArray<z.ZodString, 'many'>>;
|
||||
showCounts: z.ZodOptional<z.ZodBoolean>;
|
||||
helperText: z.ZodOptional<z.ZodString>;
|
||||
},
|
||||
'strip',
|
||||
z.ZodTypeAny,
|
||||
{
|
||||
export const EntityTagsPickerUiOptionsSchema: {
|
||||
jsonSchema: JSONSchema7;
|
||||
schemaType: {
|
||||
showCounts?: boolean | undefined;
|
||||
kinds?: string[] | undefined;
|
||||
helperText?: string | undefined;
|
||||
},
|
||||
{
|
||||
showCounts?: boolean | undefined;
|
||||
kinds?: string[] | undefined;
|
||||
helperText?: string | undefined;
|
||||
}
|
||||
>;
|
||||
};
|
||||
};
|
||||
|
||||
// @public
|
||||
export type FieldExtensionComponent<_TReturnValue, _TInputProps> = () => null;
|
||||
@@ -288,35 +261,19 @@ export const OwnedEntityPickerFieldExtension: FieldExtensionComponent<
|
||||
>;
|
||||
|
||||
// @public
|
||||
export type OwnedEntityPickerUiOptions = z.infer<
|
||||
typeof OwnedEntityPickerUiOptionsSchema
|
||||
>;
|
||||
export type OwnedEntityPickerUiOptions =
|
||||
typeof OwnedEntityPickerUiOptionsSchema.schemaType;
|
||||
|
||||
// @public (undocumented)
|
||||
export const OwnedEntityPickerUiOptionsSchema: z.ZodObject<
|
||||
{
|
||||
allowedKinds: z.ZodOptional<z.ZodArray<z.ZodString, 'many'>>;
|
||||
defaultKind: z.ZodOptional<z.ZodString>;
|
||||
allowArbitraryValues: z.ZodOptional<z.ZodBoolean>;
|
||||
defaultNamespace: z.ZodOptional<
|
||||
z.ZodUnion<[z.ZodString, z.ZodLiteral<false>]>
|
||||
>;
|
||||
},
|
||||
'strip',
|
||||
z.ZodTypeAny,
|
||||
{
|
||||
export const OwnedEntityPickerUiOptionsSchema: {
|
||||
jsonSchema: JSONSchema7;
|
||||
schemaType: {
|
||||
defaultKind?: string | undefined;
|
||||
defaultNamespace?: string | false | undefined;
|
||||
allowedKinds?: string[] | undefined;
|
||||
allowArbitraryValues?: boolean | undefined;
|
||||
},
|
||||
{
|
||||
defaultKind?: string | undefined;
|
||||
defaultNamespace?: string | false | undefined;
|
||||
allowedKinds?: string[] | undefined;
|
||||
allowArbitraryValues?: boolean | undefined;
|
||||
}
|
||||
>;
|
||||
};
|
||||
};
|
||||
|
||||
// @public
|
||||
export const OwnerPickerFieldExtension: FieldExtensionComponent<
|
||||
@@ -329,30 +286,17 @@ export const OwnerPickerFieldExtension: FieldExtensionComponent<
|
||||
>;
|
||||
|
||||
// @public
|
||||
export type OwnerPickerUiOptions = z.infer<typeof OwnerPickerUiOptionsSchema>;
|
||||
export type OwnerPickerUiOptions = typeof OwnerPickerUiOptionsSchema.schemaType;
|
||||
|
||||
// @public (undocumented)
|
||||
export const OwnerPickerUiOptionsSchema: z.ZodObject<
|
||||
{
|
||||
allowedKinds: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, 'many'>>>;
|
||||
allowArbitraryValues: z.ZodOptional<z.ZodBoolean>;
|
||||
defaultNamespace: z.ZodOptional<
|
||||
z.ZodUnion<[z.ZodString, z.ZodLiteral<false>]>
|
||||
>;
|
||||
},
|
||||
'strip',
|
||||
z.ZodTypeAny,
|
||||
{
|
||||
export const OwnerPickerUiOptionsSchema: {
|
||||
jsonSchema: JSONSchema7;
|
||||
schemaType: {
|
||||
defaultNamespace?: string | false | undefined;
|
||||
allowedKinds?: string[] | undefined;
|
||||
allowArbitraryValues?: boolean | undefined;
|
||||
},
|
||||
{
|
||||
defaultNamespace?: string | false | undefined;
|
||||
allowedKinds?: string[] | undefined;
|
||||
allowArbitraryValues?: boolean | undefined;
|
||||
}
|
||||
>;
|
||||
};
|
||||
};
|
||||
|
||||
// @public
|
||||
export const repoPickerValidation: (
|
||||
@@ -389,81 +333,13 @@ export const RepoUrlPickerFieldExtension: FieldExtensionComponent<
|
||||
>;
|
||||
|
||||
// @public
|
||||
export type RepoUrlPickerUiOptions = z.infer<
|
||||
typeof RepoUrlPickerUiOptionsSchema
|
||||
>;
|
||||
export type RepoUrlPickerUiOptions =
|
||||
typeof RepoUrlPickerUiOptionsSchema.schemaType;
|
||||
|
||||
// @public (undocumented)
|
||||
export const RepoUrlPickerUiOptionsSchema: z.ZodObject<
|
||||
{
|
||||
allowedHosts: z.ZodOptional<z.ZodArray<z.ZodString, 'many'>>;
|
||||
allowedOrganizations: z.ZodOptional<z.ZodArray<z.ZodString, 'many'>>;
|
||||
allowedOwners: z.ZodOptional<z.ZodArray<z.ZodString, 'many'>>;
|
||||
allowedRepos: z.ZodOptional<z.ZodArray<z.ZodString, 'many'>>;
|
||||
requestUserCredentials: z.ZodOptional<
|
||||
z.ZodObject<
|
||||
{
|
||||
secretsKey: z.ZodString;
|
||||
additionalScopes: z.ZodOptional<
|
||||
z.ZodObject<
|
||||
{
|
||||
gerrit: z.ZodOptional<z.ZodArray<z.ZodString, 'many'>>;
|
||||
github: z.ZodOptional<z.ZodArray<z.ZodString, 'many'>>;
|
||||
gitlab: z.ZodOptional<z.ZodArray<z.ZodString, 'many'>>;
|
||||
bitbucket: z.ZodOptional<z.ZodArray<z.ZodString, 'many'>>;
|
||||
azure: z.ZodOptional<z.ZodArray<z.ZodString, 'many'>>;
|
||||
},
|
||||
'strip',
|
||||
z.ZodTypeAny,
|
||||
{
|
||||
azure?: string[] | undefined;
|
||||
github?: string[] | undefined;
|
||||
gitlab?: string[] | undefined;
|
||||
bitbucket?: string[] | undefined;
|
||||
gerrit?: string[] | undefined;
|
||||
},
|
||||
{
|
||||
azure?: string[] | undefined;
|
||||
github?: string[] | undefined;
|
||||
gitlab?: string[] | undefined;
|
||||
bitbucket?: string[] | undefined;
|
||||
gerrit?: string[] | undefined;
|
||||
}
|
||||
>
|
||||
>;
|
||||
},
|
||||
'strip',
|
||||
z.ZodTypeAny,
|
||||
{
|
||||
additionalScopes?:
|
||||
| {
|
||||
azure?: string[] | undefined;
|
||||
github?: string[] | undefined;
|
||||
gitlab?: string[] | undefined;
|
||||
bitbucket?: string[] | undefined;
|
||||
gerrit?: string[] | undefined;
|
||||
}
|
||||
| undefined;
|
||||
secretsKey: string;
|
||||
},
|
||||
{
|
||||
additionalScopes?:
|
||||
| {
|
||||
azure?: string[] | undefined;
|
||||
github?: string[] | undefined;
|
||||
gitlab?: string[] | undefined;
|
||||
bitbucket?: string[] | undefined;
|
||||
gerrit?: string[] | undefined;
|
||||
}
|
||||
| undefined;
|
||||
secretsKey: string;
|
||||
}
|
||||
>
|
||||
>;
|
||||
},
|
||||
'strip',
|
||||
z.ZodTypeAny,
|
||||
{
|
||||
export const RepoUrlPickerUiOptionsSchema: {
|
||||
jsonSchema: JSONSchema7;
|
||||
schemaType: {
|
||||
allowedOwners?: string[] | undefined;
|
||||
allowedOrganizations?: string[] | undefined;
|
||||
allowedRepos?: string[] | undefined;
|
||||
@@ -482,28 +358,8 @@ export const RepoUrlPickerUiOptionsSchema: z.ZodObject<
|
||||
secretsKey: string;
|
||||
}
|
||||
| undefined;
|
||||
},
|
||||
{
|
||||
allowedOwners?: string[] | undefined;
|
||||
allowedOrganizations?: string[] | undefined;
|
||||
allowedRepos?: string[] | undefined;
|
||||
allowedHosts?: string[] | undefined;
|
||||
requestUserCredentials?:
|
||||
| {
|
||||
additionalScopes?:
|
||||
| {
|
||||
azure?: string[] | undefined;
|
||||
github?: string[] | undefined;
|
||||
gitlab?: string[] | undefined;
|
||||
bitbucket?: string[] | undefined;
|
||||
gerrit?: string[] | undefined;
|
||||
}
|
||||
| undefined;
|
||||
secretsKey: string;
|
||||
}
|
||||
| undefined;
|
||||
}
|
||||
>;
|
||||
};
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export const rootRouteRef: RouteRef<undefined>;
|
||||
|
||||
@@ -13,18 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
import { z } from 'zod';
|
||||
import zodToJsonSchema from 'zod-to-json-schema';
|
||||
import { makeJsonSchemaFromZod } from '../utils';
|
||||
|
||||
const EntityNamePickerReturnValueSchema = z.string();
|
||||
const EntityNamePickerReturnValueSchema = makeJsonSchemaFromZod(z.string());
|
||||
|
||||
export type EntityNamePickerReturnValue = z.infer<
|
||||
typeof EntityNamePickerReturnValueSchema
|
||||
>;
|
||||
export type EntityNamePickerReturnValue =
|
||||
typeof EntityNamePickerReturnValueSchema.schemaType;
|
||||
|
||||
export const EntityNamePickerSchema = {
|
||||
returnValue: zodToJsonSchema(
|
||||
EntityNamePickerReturnValueSchema,
|
||||
) as JSONSchema7,
|
||||
returnValue: EntityNamePickerReturnValueSchema.jsonSchema,
|
||||
};
|
||||
|
||||
@@ -13,37 +13,38 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
import { z } from 'zod';
|
||||
import zodToJsonSchema from 'zod-to-json-schema';
|
||||
import { makeJsonSchemaFromZod } from '../utils';
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const EntityPickerUiOptionsSchema = z.object({
|
||||
allowedKinds: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('List of kinds of entities to derive options from'),
|
||||
defaultKind: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'The default entity kind. Options of this kind will not be prefixed.',
|
||||
),
|
||||
allowArbitraryValues: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe('Whether to allow arbitrary user input. Defaults to true'),
|
||||
defaultNamespace: z
|
||||
.union([z.string(), z.literal(false)])
|
||||
.optional()
|
||||
.describe(
|
||||
'The default namespace. Options with this namespace will not be prefixed.',
|
||||
),
|
||||
});
|
||||
export const EntityPickerUiOptionsSchema = makeJsonSchemaFromZod(
|
||||
z.object({
|
||||
allowedKinds: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('List of kinds of entities to derive options from'),
|
||||
defaultKind: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'The default entity kind. Options of this kind will not be prefixed.',
|
||||
),
|
||||
allowArbitraryValues: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe('Whether to allow arbitrary user input. Defaults to true'),
|
||||
defaultNamespace: z
|
||||
.union([z.string(), z.literal(false)])
|
||||
.optional()
|
||||
.describe(
|
||||
'The default namespace. Options with this namespace will not be prefixed.',
|
||||
),
|
||||
}),
|
||||
);
|
||||
|
||||
const EntityPickerReturnValueSchema = z.string();
|
||||
const EntityPickerReturnValueSchema = makeJsonSchemaFromZod(z.string());
|
||||
|
||||
/**
|
||||
* The input props that can be specified under `ui:options` for the
|
||||
@@ -51,13 +52,13 @@ const EntityPickerReturnValueSchema = z.string();
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type EntityPickerUiOptions = z.infer<typeof EntityPickerUiOptionsSchema>;
|
||||
export type EntityPickerUiOptions =
|
||||
typeof EntityPickerUiOptionsSchema.schemaType;
|
||||
|
||||
export type EntityPickerReturnValue = z.infer<
|
||||
typeof EntityPickerReturnValueSchema
|
||||
>;
|
||||
export type EntityPickerReturnValue =
|
||||
typeof EntityPickerReturnValueSchema.schemaType;
|
||||
|
||||
export const EntityPickerSchema = {
|
||||
uiOptions: zodToJsonSchema(EntityPickerUiOptionsSchema) as JSONSchema7,
|
||||
returnValue: zodToJsonSchema(EntityPickerReturnValueSchema) as JSONSchema7,
|
||||
uiOptions: EntityPickerUiOptionsSchema.jsonSchema,
|
||||
returnValue: EntityPickerReturnValueSchema.jsonSchema,
|
||||
};
|
||||
|
||||
@@ -13,26 +13,29 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
import { z } from 'zod';
|
||||
import zodToJsonSchema from 'zod-to-json-schema';
|
||||
import { makeJsonSchemaFromZod } from '../utils';
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const EntityTagsPickerUiOptionsSchema = z.object({
|
||||
kinds: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('List of kinds of entities to derive tags from'),
|
||||
showCounts: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe('Whether to show usage counts per tag'),
|
||||
helperText: z.string().optional().describe('Helper text to display'),
|
||||
});
|
||||
export const EntityTagsPickerUiOptionsSchema = makeJsonSchemaFromZod(
|
||||
z.object({
|
||||
kinds: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('List of kinds of entities to derive tags from'),
|
||||
showCounts: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe('Whether to show usage counts per tag'),
|
||||
helperText: z.string().optional().describe('Helper text to display'),
|
||||
}),
|
||||
);
|
||||
|
||||
const EntityTagsPickerReturnValueSchema = z.array(z.string());
|
||||
const EntityTagsPickerReturnValueSchema = makeJsonSchemaFromZod(
|
||||
z.array(z.string()),
|
||||
);
|
||||
|
||||
/**
|
||||
* The input props that can be specified under `ui:options` for the
|
||||
@@ -40,17 +43,13 @@ const EntityTagsPickerReturnValueSchema = z.array(z.string());
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type EntityTagsPickerUiOptions = z.infer<
|
||||
typeof EntityTagsPickerUiOptionsSchema
|
||||
>;
|
||||
export type EntityTagsPickerUiOptions =
|
||||
typeof EntityTagsPickerUiOptionsSchema.schemaType;
|
||||
|
||||
export type EntityTagsPickerReturnValue = z.infer<
|
||||
typeof EntityTagsPickerReturnValueSchema
|
||||
>;
|
||||
export type EntityTagsPickerReturnValue =
|
||||
typeof EntityTagsPickerReturnValueSchema.schemaType;
|
||||
|
||||
export const EntityTagsPickerSchema = {
|
||||
uiOptions: zodToJsonSchema(EntityTagsPickerUiOptionsSchema) as JSONSchema7,
|
||||
returnValue: zodToJsonSchema(
|
||||
EntityTagsPickerReturnValueSchema,
|
||||
) as JSONSchema7,
|
||||
uiOptions: EntityTagsPickerUiOptionsSchema.jsonSchema,
|
||||
returnValue: EntityTagsPickerReturnValueSchema.jsonSchema,
|
||||
};
|
||||
|
||||
@@ -13,37 +13,38 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
import { z } from 'zod';
|
||||
import zodToJsonSchema from 'zod-to-json-schema';
|
||||
import { makeJsonSchemaFromZod } from '../utils';
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const OwnedEntityPickerUiOptionsSchema = z.object({
|
||||
allowedKinds: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('List of kinds of entities to derive options from'),
|
||||
defaultKind: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'The default entity kind. Options of this kind will not be prefixed.',
|
||||
),
|
||||
allowArbitraryValues: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe('Whether to allow arbitrary user input. Defaults to true'),
|
||||
defaultNamespace: z
|
||||
.union([z.string(), z.literal(false)])
|
||||
.optional()
|
||||
.describe(
|
||||
'The default namespace. Options with this namespace will not be prefixed.',
|
||||
),
|
||||
});
|
||||
export const OwnedEntityPickerUiOptionsSchema = makeJsonSchemaFromZod(
|
||||
z.object({
|
||||
allowedKinds: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('List of kinds of entities to derive options from'),
|
||||
defaultKind: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'The default entity kind. Options of this kind will not be prefixed.',
|
||||
),
|
||||
allowArbitraryValues: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe('Whether to allow arbitrary user input. Defaults to true'),
|
||||
defaultNamespace: z
|
||||
.union([z.string(), z.literal(false)])
|
||||
.optional()
|
||||
.describe(
|
||||
'The default namespace. Options with this namespace will not be prefixed.',
|
||||
),
|
||||
}),
|
||||
);
|
||||
|
||||
const OwnedEntityPickerReturnValueSchema = z.string();
|
||||
const OwnedEntityPickerReturnValueSchema = makeJsonSchemaFromZod(z.string());
|
||||
|
||||
/**
|
||||
* The input props that can be specified under `ui:options` for the
|
||||
@@ -51,17 +52,13 @@ const OwnedEntityPickerReturnValueSchema = z.string();
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type OwnedEntityPickerUiOptions = z.infer<
|
||||
typeof OwnedEntityPickerUiOptionsSchema
|
||||
>;
|
||||
export type OwnedEntityPickerUiOptions =
|
||||
typeof OwnedEntityPickerUiOptionsSchema.schemaType;
|
||||
|
||||
export type OwnedEntityPickerReturnValue = z.infer<
|
||||
typeof OwnedEntityPickerReturnValueSchema
|
||||
>;
|
||||
export type OwnedEntityPickerReturnValue =
|
||||
typeof OwnedEntityPickerReturnValueSchema.schemaType;
|
||||
|
||||
export const OwnedEntityPickerSchema = {
|
||||
uiOptions: zodToJsonSchema(OwnedEntityPickerUiOptionsSchema) as JSONSchema7,
|
||||
returnValue: zodToJsonSchema(
|
||||
OwnedEntityPickerReturnValueSchema,
|
||||
) as JSONSchema7,
|
||||
uiOptions: OwnedEntityPickerUiOptionsSchema.jsonSchema,
|
||||
returnValue: OwnedEntityPickerReturnValueSchema.jsonSchema,
|
||||
};
|
||||
|
||||
@@ -13,34 +13,35 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
import { z } from 'zod';
|
||||
import zodToJsonSchema from 'zod-to-json-schema';
|
||||
import { makeJsonSchemaFromZod } from '../utils';
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const OwnerPickerUiOptionsSchema = z.object({
|
||||
allowedKinds: z
|
||||
.array(z.string())
|
||||
.default(['Group', 'User'])
|
||||
.optional()
|
||||
.describe(
|
||||
'List of kinds of entities to derive options from. Defaults to Group and User',
|
||||
),
|
||||
allowArbitraryValues: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe('Whether to allow arbitrary user input. Defaults to true'),
|
||||
defaultNamespace: z
|
||||
.union([z.string(), z.literal(false)])
|
||||
.optional()
|
||||
.describe(
|
||||
'The default namespace. Options with this namespace will not be prefixed.',
|
||||
),
|
||||
});
|
||||
export const OwnerPickerUiOptionsSchema = makeJsonSchemaFromZod(
|
||||
z.object({
|
||||
allowedKinds: z
|
||||
.array(z.string())
|
||||
.default(['Group', 'User'])
|
||||
.optional()
|
||||
.describe(
|
||||
'List of kinds of entities to derive options from. Defaults to Group and User',
|
||||
),
|
||||
allowArbitraryValues: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe('Whether to allow arbitrary user input. Defaults to true'),
|
||||
defaultNamespace: z
|
||||
.union([z.string(), z.literal(false)])
|
||||
.optional()
|
||||
.describe(
|
||||
'The default namespace. Options with this namespace will not be prefixed.',
|
||||
),
|
||||
}),
|
||||
);
|
||||
|
||||
const OwnerPickerReturnValueSchema = z.string();
|
||||
const OwnerPickerReturnValueSchema = makeJsonSchemaFromZod(z.string());
|
||||
|
||||
/**
|
||||
* The input props that can be specified under `ui:options` for the
|
||||
@@ -48,13 +49,12 @@ const OwnerPickerReturnValueSchema = z.string();
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type OwnerPickerUiOptions = z.infer<typeof OwnerPickerUiOptionsSchema>;
|
||||
export type OwnerPickerUiOptions = typeof OwnerPickerUiOptionsSchema.schemaType;
|
||||
|
||||
export type OwnerPickerReturnValue = z.infer<
|
||||
typeof OwnerPickerReturnValueSchema
|
||||
>;
|
||||
export type OwnerPickerReturnValue =
|
||||
typeof OwnerPickerReturnValueSchema.schemaType;
|
||||
|
||||
export const OwnerPickerSchema = {
|
||||
uiOptions: zodToJsonSchema(OwnerPickerUiOptionsSchema) as JSONSchema7,
|
||||
returnValue: zodToJsonSchema(OwnerPickerReturnValueSchema) as JSONSchema7,
|
||||
uiOptions: OwnerPickerUiOptionsSchema.jsonSchema,
|
||||
returnValue: OwnerPickerReturnValueSchema.jsonSchema,
|
||||
};
|
||||
|
||||
@@ -13,70 +13,71 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
import { z } from 'zod';
|
||||
import zodToJsonSchema from 'zod-to-json-schema';
|
||||
import { makeJsonSchemaFromZod } from '../utils';
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const RepoUrlPickerUiOptionsSchema = z.object({
|
||||
allowedHosts: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('List of allowed SCM platform hosts'),
|
||||
allowedOrganizations: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('List of allowed organizations in the given SCM platform'),
|
||||
allowedOwners: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('List of allowed owners in the given SCM platform'),
|
||||
allowedRepos: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('List of allowed repos in the given SCM platform'),
|
||||
requestUserCredentials: z
|
||||
.object({
|
||||
secretsKey: z
|
||||
.string()
|
||||
.describe(
|
||||
'Key used within the template secrets context to store the credential',
|
||||
),
|
||||
additionalScopes: z
|
||||
.object({
|
||||
gerrit: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('Additional Gerrit scopes to request'),
|
||||
github: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('Additional GitHub scopes to request'),
|
||||
gitlab: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('Additional GitLab scopes to request'),
|
||||
bitbucket: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('Additional BitBucket scopes to request'),
|
||||
azure: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('Additional Azure scopes to request'),
|
||||
})
|
||||
.optional()
|
||||
.describe('Additional permission scopes to request'),
|
||||
})
|
||||
.optional()
|
||||
.describe(
|
||||
'If defined will request user credentials to auth against the given SCM platform',
|
||||
),
|
||||
});
|
||||
export const RepoUrlPickerUiOptionsSchema = makeJsonSchemaFromZod(
|
||||
z.object({
|
||||
allowedHosts: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('List of allowed SCM platform hosts'),
|
||||
allowedOrganizations: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('List of allowed organizations in the given SCM platform'),
|
||||
allowedOwners: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('List of allowed owners in the given SCM platform'),
|
||||
allowedRepos: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('List of allowed repos in the given SCM platform'),
|
||||
requestUserCredentials: z
|
||||
.object({
|
||||
secretsKey: z
|
||||
.string()
|
||||
.describe(
|
||||
'Key used within the template secrets context to store the credential',
|
||||
),
|
||||
additionalScopes: z
|
||||
.object({
|
||||
gerrit: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('Additional Gerrit scopes to request'),
|
||||
github: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('Additional GitHub scopes to request'),
|
||||
gitlab: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('Additional GitLab scopes to request'),
|
||||
bitbucket: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('Additional BitBucket scopes to request'),
|
||||
azure: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe('Additional Azure scopes to request'),
|
||||
})
|
||||
.optional()
|
||||
.describe('Additional permission scopes to request'),
|
||||
})
|
||||
.optional()
|
||||
.describe(
|
||||
'If defined will request user credentials to auth against the given SCM platform',
|
||||
),
|
||||
}),
|
||||
);
|
||||
|
||||
const RepoUrlPickerReturnValueSchema = z.string();
|
||||
const RepoUrlPickerReturnValueSchema = makeJsonSchemaFromZod(z.string());
|
||||
|
||||
/**
|
||||
* The input props that can be specified under `ui:options` for the
|
||||
@@ -84,18 +85,16 @@ const RepoUrlPickerReturnValueSchema = z.string();
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type RepoUrlPickerUiOptions = z.infer<
|
||||
typeof RepoUrlPickerUiOptionsSchema
|
||||
>;
|
||||
export type RepoUrlPickerUiOptions =
|
||||
typeof RepoUrlPickerUiOptionsSchema.schemaType;
|
||||
|
||||
export type RepoUrlPickerReturnValue = z.infer<
|
||||
typeof RepoUrlPickerReturnValueSchema
|
||||
>;
|
||||
export type RepoUrlPickerReturnValue =
|
||||
typeof RepoUrlPickerReturnValueSchema.schemaType;
|
||||
|
||||
// NOTE: There is a bug with this failing validation in the custom field explorer due
|
||||
// to https://github.com/rjsf-team/react-jsonschema-form/issues/675 even if
|
||||
// requestUserCredentials is not defined
|
||||
export const RepoUrlPickerSchema = {
|
||||
uiOptions: zodToJsonSchema(RepoUrlPickerUiOptionsSchema) as JSONSchema7,
|
||||
returnValue: zodToJsonSchema(RepoUrlPickerReturnValueSchema) as JSONSchema7,
|
||||
uiOptions: RepoUrlPickerUiOptionsSchema.jsonSchema,
|
||||
returnValue: RepoUrlPickerReturnValueSchema.jsonSchema,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2022 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 { JSONSchema7 } from 'json-schema';
|
||||
import { z } from 'zod';
|
||||
import zodToJsonSchema from 'zod-to-json-schema';
|
||||
|
||||
/**
|
||||
* Utility function to convert zod schemas to JSON schemas with
|
||||
* type inference extraction that abstracts away zod typings
|
||||
*/
|
||||
export function makeJsonSchemaFromZod<T extends z.ZodType>(
|
||||
schema: T,
|
||||
): {
|
||||
jsonSchema: JSONSchema7;
|
||||
schemaType: T extends z.ZodType<any, any, infer I> ? I : never;
|
||||
} {
|
||||
return {
|
||||
jsonSchema: zodToJsonSchema(schema) as JSONSchema7,
|
||||
schemaType: null as any,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user