diff --git a/web-console-v2/src/pages/StepsPages/Ingestion/Ingestion.tsx b/web-console-v2/src/pages/StepsPages/Ingestion/Ingestion.tsx index 07bc69c0..91abd5ee 100644 --- a/web-console-v2/src/pages/StepsPages/Ingestion/Ingestion.tsx +++ b/web-console-v2/src/pages/StepsPages/Ingestion/Ingestion.tsx @@ -17,6 +17,7 @@ import UploadFiles from 'pages/Dataset/wizard/UploadFiles'; import React, { useEffect, useMemo, useRef, useState } from 'react'; import { useLocation, useNavigate, useParams } from 'react-router-dom'; import { + isJsonSchema, useCreateDataset, useFetchDatasetExists, useFetchDatasetsById, @@ -28,7 +29,6 @@ import { } from 'services/dataset'; import { readJsonFileContents } from 'services/utils'; import { theme } from 'theme'; -import Ajv from "ajv"; import { default as ingestionStyle, default as localStyles } from './Ingestion.module.css'; interface FormData { @@ -46,15 +46,6 @@ const GenericCard = styled(Card)(({ theme }) => ({ boxShadow: 'none', margin: theme.spacing(0, 6, 2, 2) })); -const ajv = new Ajv({strict: false}); -const isJsonSchema = (jsonObject: any) => { - try { - ajv.compile(jsonObject); - return true; // If no errors, it's a valid JSON Schema - } catch (err) { - return false; // Not a valid JSON Schema - } -} const MAX_FILES = 10; diff --git a/web-console-v2/src/services/dataset.ts b/web-console-v2/src/services/dataset.ts index 45e2d935..d8bae29a 100644 --- a/web-console-v2/src/services/dataset.ts +++ b/web-console-v2/src/services/dataset.ts @@ -5,7 +5,6 @@ import _ from 'lodash'; import { fetchSessionStorageItem, storeSessionStorageItem } from 'utils/sessionStorage'; import { generateRequestBody, setDatasetId, setVersionKey, transformResponse } from './utils'; import { queryClient } from 'queryClient'; -import apiEndpoints from 'data/apiEndpoints'; // const ENDPOINTS = { // DATASETS_READ: '/console/config/v2/datasets/read', @@ -256,4 +255,33 @@ const omitSuggestions = (schema: any): any => { export const getConfigValue = (variable: string) => { const config: string | any = sessionStorage.getItem('systemSettings'); return _.get(JSON.parse(config), variable); -}; \ No newline at end of file +}; + +export const isJsonSchema = (jsonObject: any) => { + if (typeof jsonObject !== "object" || jsonObject === null) { + return false; + } + const schemaKeywords = [ + "$schema", + "type", + "properties", + "required", + "additionalProperties", + "definitions", + "items", + "allOf", + "oneOf", + "anyOf", + "not", + ]; + + const hasSchemaKeyword = schemaKeywords.some((keyword) => + Object.prototype.hasOwnProperty.call(jsonObject, keyword) + ); + + if (!hasSchemaKeyword) { + return false; + } else { + return true; + } +} \ No newline at end of file