Skip to content

Commit

Permalink
Updating the resolv eref
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshibobade21 committed Aug 21, 2024
1 parent 1e8f757 commit 5435dbb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/renderer/components/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ const Home = () => {
...connectionStore["ftp-details"],
password: "",
connectionType: 'ftp',
jobStatement: jobStatement };
jobStatement: jobStatement};
dispatch(setConnectionArgs(connectionArgs));
dispatch(setJobStatement(jobStatement));
} else {
Expand Down
23 changes: 12 additions & 11 deletions src/services/ResolveRef.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
let mainSchema: any;
let schemaMap: { [key: string]: any } = {};

export const updateSchemaReferences = (yamlAndSchema: any, schemaObject: any): void => {
mainSchema = schemaObject;
const schemaArray = Object.keys(yamlAndSchema);
const schemaMap: {[key: string]: any} = {};
schemaMap = {};

schemaArray.forEach(key => {
const value = yamlAndSchema[key];
Expand All @@ -18,28 +19,28 @@ export const updateSchemaReferences = (yamlAndSchema: any, schemaObject: any): v
}
});

traverseAndResolveReferences(schemaObject, schemaMap);
traverseAndResolveReferences(schemaObject);
}

const traverseAndResolveReferences = (node: any, schemaMap: {[key: string]: any}) => {
if (node && typeof node === "object") {
Object.keys(node).forEach((key) => {
if (key === "$ref" && typeof node[key] === "string") {
const traverseAndResolveReferences = (schemaObj: any) => {
if (schemaObj && typeof schemaObj === "object") {
Object.keys(schemaObj).forEach((key) => {
if (key === "$ref" && typeof schemaObj[key] === "string") {
try {
const refValue = resolveRef(node[key], schemaMap);
Object.assign(node, refValue);
delete node['$ref'];
const refValue = resolveRef(schemaObj[key]);
Object.assign(schemaObj, refValue);
delete schemaObj['$ref'];
} catch(error){
console.error("Error resolving reference:", error.message);
}
} else {
traverseAndResolveReferences(node[key], schemaMap);
traverseAndResolveReferences(schemaObj[key]);
}
})
}
}

const resolveRef = (ref: string, schemaMap: any) => {
const resolveRef = (ref: string) => {
let [refPath, anchorPart] = ref.split('#');
const isRefPathEmpty = !refPath;

Expand Down

0 comments on commit 5435dbb

Please sign in to comment.