Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
  • Loading branch information
freben committed Feb 16, 2022
1 parent 6fe01ce commit 5e585bb
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-tables-grab.md
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-common': minor
---

**BREAKING**: Removed the `templateEntityV1beta3Schema` export
Expand Up @@ -21,7 +21,6 @@ import {
parseEntityRef,
RELATION_OWNED_BY,
RELATION_OWNER_OF,
entityKindSchemaValidator,
} from '@backstage/catalog-model';
import {
CatalogProcessor,
Expand All @@ -30,18 +29,16 @@ import {
} from '@backstage/plugin-catalog-backend';
import {
TemplateEntityV1beta3,
templateEntityV1beta3Schema,
templateEntityV1beta3Validator,
} from '@backstage/plugin-scaffolder-common';

/** @public */
export class ScaffolderEntitiesProcessor implements CatalogProcessor {
private readonly validators = [
entityKindSchemaValidator(templateEntityV1beta3Schema),
];
private readonly validators = [templateEntityV1beta3Validator];

async validateEntityKind(entity: Entity): Promise<boolean> {
for (const validator of this.validators) {
if (validator(entity)) {
if (await validator.check(entity)) {
return true;
}
}
Expand Down
6 changes: 1 addition & 5 deletions plugins/scaffolder-common/api-report.md
Expand Up @@ -5,7 +5,6 @@
```ts
import { Entity } from '@backstage/catalog-model';
import { JsonObject } from '@backstage/types';
import { JSONSchema } from '@backstage/catalog-model';
import { JsonValue } from '@backstage/types';
import { KindValidator } from '@backstage/catalog-model';

Expand Down Expand Up @@ -86,9 +85,6 @@ export interface TemplateEntityV1beta2 extends Entity {
};
}

// @public @deprecated
export const templateEntityV1beta2Schema: JSONSchema;

// @public @deprecated
export const templateEntityV1beta2Validator: KindValidator;

Expand Down Expand Up @@ -117,7 +113,7 @@ export interface TemplateEntityV1beta3 extends Entity {
}

// @public
export const templateEntityV1beta3Schema: JSONSchema;
export const templateEntityV1beta3Validator: KindValidator;

// @public
export type TemplateMetadata = {
Expand Down
13 changes: 0 additions & 13 deletions plugins/scaffolder-common/src/TemplateEntityV1beta2.ts
Expand Up @@ -17,7 +17,6 @@
import {
Entity,
entityKindSchemaValidator,
JSONSchema,
KindValidator,
} from '@backstage/catalog-model';
import { JsonObject } from '@backstage/types';
Expand Down Expand Up @@ -51,18 +50,6 @@ export interface TemplateEntityV1beta2 extends Entity {

const validator = entityKindSchemaValidator(schema);

/**
* JSON schema of the Template kind, apiVersion backstage.io/v1beta2.
*
* @public
* @deprecated Please convert your templates to apiVersion
* scaffolder.backstage.io/v1beta3
*/
export const templateEntityV1beta2Schema: JSONSchema = schema as Omit<
JSONSchema,
'examples'
>;

/**
* Entity data validator for {@link TemplateEntityV1beta2}.
*
Expand Down
22 changes: 15 additions & 7 deletions plugins/scaffolder-common/src/TemplateEntityV1beta3.ts
Expand Up @@ -14,9 +14,13 @@
* limitations under the License.
*/

import { Entity, JSONSchema } from '@backstage/catalog-model';
import {
Entity,
entityKindSchemaValidator,
KindValidator,
} from '@backstage/catalog-model';
import { JsonObject } from '@backstage/types';
import v1beta3Schema from './Template.v1beta3.schema.json';
import schema from './Template.v1beta3.schema.json';

/**
* Backstage catalog Template kind Entity. Templates are used by the Scaffolder
Expand All @@ -42,12 +46,16 @@ export interface TemplateEntityV1beta3 extends Entity {
};
}

const validator = entityKindSchemaValidator(schema);

/**
* JSON schema of the Template kind, apiVersion scaffolder.backstage.io/v1beta3.
* Entity data validator for {@link TemplateEntityV1beta3}.
*
* @public
*/
export const templateEntityV1beta3Schema: JSONSchema = v1beta3Schema as Omit<
JSONSchema,
'examples'
>;
export const templateEntityV1beta3Validator: KindValidator = {
// TODO(freben): Emulate the old KindValidator until we fix that type
async check(data: Entity) {
return validator(data) === data;
},
};
7 changes: 2 additions & 5 deletions plugins/scaffolder-common/src/index.ts
Expand Up @@ -21,10 +21,7 @@
*/

export * from './TaskSpec';
export {
templateEntityV1beta2Schema,
templateEntityV1beta2Validator,
} from './TemplateEntityV1beta2';
export { templateEntityV1beta2Validator } from './TemplateEntityV1beta2';
export type { TemplateEntityV1beta2 } from './TemplateEntityV1beta2';
export { templateEntityV1beta3Schema } from './TemplateEntityV1beta3';
export { templateEntityV1beta3Validator } from './TemplateEntityV1beta3';
export type { TemplateEntityV1beta3 } from './TemplateEntityV1beta3';

0 comments on commit 5e585bb

Please sign in to comment.