File tree 6 files changed +46
-3
lines changed
6 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,17 @@ export class AppConfig {
98
98
}
99
99
}
100
100
}
101
+ } ,
102
+ imprints : {
103
+ items : {
104
+ properties : {
105
+ date : {
106
+ errorMessage : {
107
+ format : 'This is not a date!'
108
+ }
109
+ }
110
+ }
111
+ }
101
112
}
102
113
}
103
114
} ,
Original file line number Diff line number Diff line change 43
43
"zone.js" : " ^0.8.4"
44
44
},
45
45
"dependencies" : {
46
- "ajv" : " ^4.11.3" ,
46
+ "ajv" : " ^5.0.0" ,
47
+ "ajv-errors" : " ^1.0.0" ,
47
48
"diff" : " ^3.3.0" ,
48
49
"immutable" : " ^3.8.1" ,
49
50
"katex" : " ^0.7.1" ,
Original file line number Diff line number Diff line change
1
+ export interface CustomErrorMessages {
2
+ pattern ?: string ;
3
+ format ?: string ;
4
+ multipleOf ?: string ;
5
+ maximum ?: string ;
6
+ exclusiveMaximum ?: string ;
7
+ minimum ?: string ;
8
+ exclusiveMinimum ?: string ;
9
+
10
+ /**
11
+ * Schema validation for pritimive types so below is not supported yet
12
+ * maxLength?: string;
13
+ * minLength?: string;
14
+ * maxItems?: string;
15
+ * minItems?: string;
16
+ * uniqueItems?: string;
17
+ * maxProperties?: string;
18
+ * minProperties?: string;
19
+ */
20
+ }
Original file line number Diff line number Diff line change @@ -27,3 +27,4 @@ export { CustomFormatValidation } from './custom-format-validation';
27
27
export { JsonPatchesByPath } from './json-patches-by-path' ;
28
28
export { ViewTemplateConfig } from './view-template-config' ;
29
29
export { ShortcutActionFunction } from './shortcut-action-function' ;
30
+ export { CustomErrorMessages } from './custom-error-messages' ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { LongListNavigatorConfig } from './long-list-navigator-config';
3
3
import { ViewTemplateConfig } from './view-template-config' ;
4
4
import { RefConfig } from './ref-config' ;
5
5
import { OnValueChangeFunction } from './on-value-change-function' ;
6
+ import { CustomErrorMessages } from './custom-error-messages' ;
6
7
7
8
export interface SchemaOption {
8
9
/**
@@ -109,4 +110,9 @@ export interface SchemaOption {
109
110
* Flag to enable LaTeX preview in a field.
110
111
*/
111
112
latexPreviewEnabled ?: boolean ;
113
+
114
+ /**
115
+ * Custom error messages for schema validation
116
+ */
117
+ errorMessage ?: string | CustomErrorMessages ;
112
118
}
Original file line number Diff line number Diff line change 22
22
23
23
import { Injectable } from '@angular/core' ;
24
24
import * as Ajv from 'ajv' ;
25
- import { AppGlobalsService } from './app-globals.service ' ;
25
+ import * as enableCustomErrorMessages from 'ajv-errors ' ;
26
26
27
+ import { AppGlobalsService } from './app-globals.service' ;
27
28
import { JSONSchema , ValidationError } from '../interfaces' ;
28
29
29
30
@Injectable ( )
30
31
export class SchemaValidationService {
31
32
32
- private ajv = new Ajv ( { allErrors : true } ) ;
33
+ // `jsonPointer: true` is required for `avj-errors` package
34
+ private ajv = new Ajv ( { allErrors : true , jsonPointers : true } ) ;
33
35
34
36
// https://gist.github.com/dperini/729294
35
37
private reWebUrl = new RegExp (
@@ -72,6 +74,8 @@ export class SchemaValidationService {
72
74
) ;
73
75
74
76
constructor ( public appGlobalsService : AppGlobalsService ) {
77
+ enableCustomErrorMessages ( this . ajv ) ;
78
+
75
79
// ajv didn't support format:url, so was added using web url regex for validation
76
80
this . ajv . addFormat ( 'url' , this . reWebUrl ) ;
77
81
if ( this . appGlobalsService . config && this . appGlobalsService . config . customFormatValidation ) {
You can’t perform that action at this time.
0 commit comments