Skip to content

Commit 83295b5

Browse files
committed
feat: add support for json schema 07 validation in validateJson
1 parent ee27297 commit 83295b5

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.2.5-beta-4",
3+
"version": "1.2.5-beta-6",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",
@@ -95,6 +95,7 @@
9595
},
9696
"dependencies": {
9797
"@types/react-dates": "^21.8.6",
98+
"ajv": "8.17.1",
9899
"ansi_up": "^5.2.1",
99100
"dayjs": "^1.11.13",
100101
"fast-json-patch": "^3.1.1",

src/Shared/validations.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import { getSanitizedIframe } from '@Common/Helper'
18+
import SchemaValidator from 'ajv'
1819
import { URLProtocolType } from './types'
1920

2021
export interface ValidationResponseType {
@@ -333,7 +334,12 @@ export const validateDisplayName = (name: string): ValidationResponseType =>
333334
export const validateJSON = (json: string): ValidationResponseType => {
334335
try {
335336
if (json) {
336-
JSON.parse(json)
337+
const parsedJson = JSON.parse(json)
338+
339+
// NOTE: Ajv uses json schema draft 07 by default
340+
// if compile step doesn't throw any errors we can safely say the
341+
// json schema is correct
342+
new SchemaValidator({ strict: true }).compile(parsedJson)
337343
}
338344
return {
339345
isValid: true,

0 commit comments

Comments
 (0)