Skip to content

Commit

Permalink
Update Schema Name and Field Validation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcibotari committed Dec 16, 2024
1 parent d110246 commit 576ea09
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/app/shared/validators/common.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ export class CommonValidator {
}
}

export const RESERVED_NAMES = ['_id', 'schema', 'kind'];

export enum CommonPattern {
JSON_NAME = '[a-z]+[a-zA-Z0-9_]*[a-zA-Z0-9]+',
URL_SLUG = '[a-z]+[a-zA-Z0-9-_]*[a-zA-Z0-9]+',
Expand Down
19 changes: 17 additions & 2 deletions src/app/shared/validators/schema.validator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { ValidatorFn, Validators } from '@angular/forms';
import { CommonPattern, CommonValidator, RESERVED_NAMES } from './common.validator';
import { CommonPattern, CommonValidator } from './common.validator';

const SCHEMA_RESERVED_IDS = [
'Translations',
'Links',
'ContentMetadata',
'ContentReference',
'ContentRichText',
'ContentLink',
'ContentData',
'ContentAsset',
'Content',
];

const SCHEMA_RESERVED_FIELD_NAMES = ['_id', 'schema'];

export class SchemaValidator {
public static ID: ValidatorFn[] = [
Validators.required,
CommonValidator.noSpace,
Validators.pattern(CommonPattern.SCHEMA_ID),
CommonValidator.reservedName(SCHEMA_RESERVED_IDS),
Validators.minLength(3),
Validators.maxLength(50),
];
Expand All @@ -22,8 +37,8 @@ export class SchemaValidator {
public static FIELD_NAME: ValidatorFn[] = [
Validators.required,
CommonValidator.noSpace,
CommonValidator.reservedName(RESERVED_NAMES),
Validators.pattern(CommonPattern.JSON_NAME),
CommonValidator.reservedName(SCHEMA_RESERVED_FIELD_NAMES),
Validators.minLength(2),
Validators.maxLength(30),
];
Expand Down

0 comments on commit 576ea09

Please sign in to comment.