Reputation: 307
I try to use 'akorchev/odata2openapi' module to transform odata metadata.xml file into json. As per documentation, I have implemented the following code:
const o2oapi = require('odata2openapi');
function_B (content) {
o2oapi.parse(content)
.then(entitySets => convert(entitySets))
.then(swagger => console.log(JSON.stringify(swagger, null, 2)))
.catch(error => console.error(error));
}
The content variable is a metadata xml stream that I can display on console. I can also see the following result when logging the parse method of function B:
Promise {
{ entitySets: [ [Object], [Object] ],
version: '1.0',
complexTypes: [],
singletons: [],
actions: [],
functions: [],
defaultNamespace: 'ZEXAMPLE_SRV',
entityTypes: [ [Object], [Object] ] } }
Unfortunately, I am not able to get the final result 'from swagger' to pass to another function C.
function_A (content, x, y, z){
function_C (function_B (content), x, y ,z);
}
I have tried to adapt my code without any success. Could you please advice?
Upvotes: 0
Views: 175
Reputation: 307
I could finally solve the issue with multiple changes. As suggested by @ethan-jewett, I had to debug the convert method to see that inputs were wrong. In addition, as suggested by @moshimoshi, I had to cascade async functions.
Here, the final code implementation of function B:
function_B(content) {
return new Promise(function (resolve, reject) {
const options = {
host: '',
path: ''
};
parse(content)
.then(entitySets => convert(entitySets.entitySets, options))
.then(function(swagger) {
var result = JSON.stringify(swagger, null, 2);
resolve(result);
})
.catch(error => {
reject(error);
});
});
}
For function A:
function_A (content, x, y, z){
function_B (content).then(result => function_C (result , x, y ,z));
}
Upvotes: 1