Skip to content
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

Add xml2json func, expandReference parseXML(body) #444

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improvements
mtuchi committed Dec 6, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
patrick-ogrady Patrick O'Grady
commit 327ffa45ed50d80127bdd43e9649783f545f2da0
10 changes: 7 additions & 3 deletions packages/http/src/Adaptor.js
Original file line number Diff line number Diff line change
@@ -331,25 +331,29 @@ export function parseXML(body, script) {
}

/**
* The parseXML2JSON function takes an XML string and converts it to a JSON object.
* The xml2json function takes an XML string and converts it to a JSON object.
*
* @param {string} xml - Pass in the xml string that we want to parse
* @param {object} options - Specify the options for the parsestring function
* @param {function} callback - (Optional) Callback function
* @returns {Operation}
*/

export function parseXML2JSON(xml, options, callback) {
export function xml2json(xml, options, callback) {
return state => {
const resolvedXml = expandReferences(xml)(state);
const resolvedOptions = expandReferences(options)(state);

let response = null;
parseString(resolvedXml, resolvedOptions, (err, result) => {
if (err) {
console.log(err, 'error');
}
console.dir(JSON.stringify(result, null, 2));
console.dir(JSON.stringify(result));
response = result;
});

return composeNextState(state, { body: response });
};
}