File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 16
16
17
17
import { forwardRef } from 'react'
18
18
import RJSF from '@rjsf/core'
19
- import RJSFValidator from '@rjsf/validator-ajv8'
20
19
21
20
import { templates , widgets } from './config'
22
21
import { FormProps } from './types'
23
22
import { translateString } from './utils'
23
+ import { SCHEMA_07_VALIDATOR_STRICT } from '@Shared/validations'
24
24
import './rjsfForm.scss'
25
25
26
26
// Need to use this way because the default import was not working as expected
27
27
// The default import resolves to an object intead of a function
28
28
const Form = RJSF
29
- const validator = RJSFValidator
29
+ const validator = SCHEMA_07_VALIDATOR_STRICT
30
30
31
31
export const RJSFForm = forwardRef ( ( props : FormProps , ref : FormProps [ 'ref' ] ) => (
32
32
< Form
Original file line number Diff line number Diff line change 15
15
*/
16
16
17
17
import { getSanitizedIframe } from '@Common/Helper'
18
+ import { customizeValidator } from '@rjsf/validator-ajv8'
18
19
import { PATTERNS } from '@Common/Constants'
19
20
import { URLProtocolType } from './types'
20
21
import { SKIP_LABEL_KEY_VALIDATION_PREFIX } from './constants'
@@ -378,10 +379,26 @@ export const validateSemanticVersioning = (version: string): ValidationResponseT
378
379
export const validateDisplayName = ( name : string ) : ValidationResponseType =>
379
380
validateStringLength ( name , DISPLAY_NAME_CONSTRAINTS . MAX_LIMIT , DISPLAY_NAME_CONSTRAINTS . MIN_LIMIT )
380
381
381
- export const validateJSON = ( json : string ) : ValidationResponseType => {
382
+ export const SCHEMA_07_VALIDATOR_STRICT = customizeValidator ( {
383
+ ajvOptionsOverrides : {
384
+ strict : true ,
385
+ allowUnionTypes : true ,
386
+ } ,
387
+ } )
388
+ SCHEMA_07_VALIDATOR_STRICT . ajv . addKeyword ( 'hidden' )
389
+ SCHEMA_07_VALIDATOR_STRICT . ajv . addFormat ( 'memory' , / ^ \d + ( \. \d + ) ? ( K i | M i | G i | T i | P i | E i | K i B | M i B | G i B | T i B | P i B | E i B ) ? $ / )
390
+ SCHEMA_07_VALIDATOR_STRICT . ajv . addFormat ( 'cpu' , / ^ (?: \d + ( \. \d + ) ? | ( \d + ) ( m ) ) $ / )
391
+
392
+ const SCHEMA_07_VALIDATOR = customizeValidator ( { ajvOptionsOverrides : { strict : false } } )
393
+ SCHEMA_07_VALIDATOR . ajv . addKeyword ( 'hidden' )
394
+
395
+ export const doesJSONConformToSchema07 = ( json : string , strict = false ) : ValidationResponseType => {
382
396
try {
383
397
if ( json ) {
384
- JSON . parse ( json )
398
+ // NOTE: if json is not parsable JSON.parse will through error
399
+ // if validators can't be compiled from the parsed json schema then
400
+ // provided json schema does not conform to json schema draft 07; again can throw error
401
+ ; ( strict ? SCHEMA_07_VALIDATOR_STRICT : SCHEMA_07_VALIDATOR ) . ajv . compile ( JSON . parse ( json ) )
385
402
}
386
403
return {
387
404
isValid : true ,
You can’t perform that action at this time.
0 commit comments