fix(scaffolder): schema adjusted

This commit is contained in:
Ivan Shmidt
2020-07-01 18:51:33 +02:00
parent e4dd9bd5b2
commit 34399824a6
6 changed files with 42 additions and 4 deletions
+1
View File
@@ -22,6 +22,7 @@
"dependencies": {
"@backstage/config": "^0.1.1-alpha.12",
"@types/yup": "^0.28.2",
"json-schema": "^0.2.5",
"lodash": "^4.17.15",
"uuid": "^8.0.0",
"yup": "^0.29.1"
@@ -33,6 +33,22 @@ describe('TemplateEntityV1alpah1', () => {
},
spec: {
type: 'cookiecutter',
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
required: ['storePath', 'owner'],
properties: {
owner: {
type: 'string',
title: 'Owner',
description: 'Who is going to own this component',
},
storePath: {
type: 'string',
title: 'Store path',
description: 'GitHub store path in org/repo format',
},
},
},
},
};
policy = new TemplateEntityV1alpha1Policy();
@@ -16,7 +16,7 @@
import * as yup from 'yup';
import type { Entity } from '../entity/Entity';
import type { EntityPolicy } from '../types';
import type { EntityPolicy, JSONSchema } from '../types';
const API_VERSION = ['backstage.io/v1alpha1', 'backstage.io/v1beta1'] as const;
const KIND = 'Template' as const;
@@ -27,6 +27,7 @@ export interface TemplateEntityV1alpha1 extends Entity {
spec: {
type: string;
path?: string;
schema: JSONSchema;
};
}
@@ -41,6 +42,7 @@ export class TemplateEntityV1alpha1Policy implements EntityPolicy {
.object({
type: yup.string().required().min(1),
path: yup.string(),
schema: yup.object().required(),
})
.required(),
});
+4
View File
@@ -14,6 +14,8 @@
* limitations under the License.
*/
import { JsonValue } from '@backstage/config';
import { JSONSchema7 } from 'json-schema';
import type { Entity } from './entity/Entity';
/**
@@ -30,3 +32,5 @@ export type EntityPolicy = {
*/
enforce(entity: Entity): Promise<Entity>;
};
export type JSONSchema = JSONSchema7 & { [key in string]?: JsonValue };
+13 -3
View File
@@ -37,20 +37,30 @@ export class ScaffolderApi {
this.basePath = basePath;
}
/**
*
* @param template Template entity for the scaffolder to use. New project is going to be created out of this template.
* @param values Parameters for the template, e.g. name, description
*/
async scaffold(
template: TemplateEntityV1alpha1,
values: Record<string, any>,
) {
const url = `${this.apiOrigin}${this.basePath}/jobs`;
const { id: jobId } = await fetch(url, {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ template, values }),
}).then(x => x.json());
});
return jobId;
if (response.status !== 201) {
throw new Error(await response.text());
}
const { id } = await response.json();
return id;
}
async getJob(jobId: string) {
+5
View File
@@ -11721,6 +11721,11 @@ json-schema@0.2.3:
resolved "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13"
integrity sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=
json-schema@^0.2.5:
version "0.2.5"
resolved "https://registry.npmjs.org/json-schema/-/json-schema-0.2.5.tgz#97997f50972dd0500214e208c407efa4b5d7063b"
integrity sha512-gWJOWYFrhQ8j7pVm0EM8Slr+EPVq1Phf6lvzvD/WCeqkrx/f2xBI0xOsRRS9xCn3I4vKtP519dvs3TP09r24wQ==
json-stable-stringify-without-jsonify@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"