-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Hardcoded Schema References #240
Merged
Merged
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2e233f0
Adding the utility functions
sakshibobade21 c9f6d1b
Removing launch config file
sakshibobade21 81a9bc1
Adding the service
sakshibobade21 8e11bcf
Updating the installation Handler
sakshibobade21 c0f1ddf
Updating the core logic
sakshibobade21 7caa479
Merge remote-tracking branch 'origin' into schema-updates
sakshibobade21 9257774
Handling reference resolving
sakshibobade21 ae43a38
Final updates
sakshibobade21 06d80a4
Merge remote-tracking branch 'origin' into schema-updates
sakshibobade21 805e724
Updatinf the functions again
sakshibobade21 1c84a38
More updates
sakshibobade21 64e3c26
Updating the param for the ref resolver
sakshibobade21 b940653
Merge branch 'v2.x/staging' into schema-updates
skurnevich 80dd90e
Merge remote-tracking branch 'origin' into schema-updates
sakshibobade21 c6a4ccd
Merge branch 'schema-updates' of https://github.com/zowe/zen into sch…
sakshibobade21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export const updateSchemaReferences = (schema: any, serverCommon: any): void => { | ||
|
||
const traverseAndUpdate = (node: any) => { | ||
if (node !== null && typeof node === "object") { | ||
for (const key in node) { | ||
if (key === "$ref" && typeof node[key] === "string") { | ||
try { | ||
const refValue = resolveRef(node[key]); | ||
Object.assign(node, refValue); | ||
delete node['$ref']; | ||
} catch(error){ | ||
console.error("Error resolving reference:", error.message); | ||
} | ||
} else { | ||
traverseAndUpdate(node[key]); | ||
} | ||
} | ||
} | ||
} | ||
|
||
const resolveRef = (ref: string) => { | ||
const refPath = ref.split('#')[1]; | ||
let result = serverCommon.$defs; | ||
const refObject = Object.values(result).find((obj:any) => obj.$anchor === refPath); | ||
return refObject; | ||
} | ||
|
||
traverseAndUpdate(schema); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we are resolving only server-common references? I do not know how likely we will have references to other schemas in future but we'd better handle it at least through log / warnings if some refs were not resolved.
Also how are internal refs handled now, like
"$ref": "#/$defs/pkcs12-certificate"
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it would be better to do
const refParts = ref.split('#');
const refFile = refParts[0];
const refAnchor = refParts[1];
if (!refFile) { refFile = zowe-yaml-schema.json }
else { // gather the $id values of each schema file and make a map so you can identify which schema file is being referenced }