Edit
So if I set a setTimeout
on my final console.log
, it will log fine, but I guess my new question is although, even with the then
statements, why isnt the it triggering after everything is resolved?
I am having an odd bug that I cant figure out why it is not printing the whole structure that I am expecting. I am not getting any errors, and I did try putting in a few console.log
, but just get seem to get the anyOf
property to log. It always shows empty.
My main issue is that hold
is not logging correctly. It is showing anyOf
as empty.
const $ = require('cheerio');
const Axios = require('axios').default;
let name = 'sqs';
let basePath = '/AWS_SQS.html'
let hold = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'$id': `cf${name}`,
'description': `CF ${name}`,
'properties': {
'Type': {
'type': 'string',
'enum': [],
},
},
'anyOf': [] // this keeps coming up empty
};
let typeProperties = (t, p) => {
return {
'if': { 'properties': { 'Type': { 'const': t } } },
'then': {
'properties': {
'Properties': {
'type': 'object',
'properties': p,
},
},
},
}
}
const makeRequest = (bpath) => {
let url = 'https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/' + bpath
return Axios.get(url)
.then((res) => {
return res.data;
})
.catch(console.log);
};
let getData = makeRequest(basePath).then((data) => {
let match = $('.listitem>p>a', data);
match.map((i, e) => {
let t = $(e);
hold.properties.Type.enum.push(t.text());
makeRequest(t.attr('href')).then((newdata) => {
let holdProperties = {}
let pType = $($('.variablelist', newdata)[0])
$('.term>.code', pType).map((i, elem) => {
let propertyName = $(elem).text()
holdProperties[propertyName] = {}
})
hold.anyOf.push(typeProperties(t.text(), holdProperties))
}).catch(console.log)
});
}).catch(console.log)
getData.then(() => {
// Why doesnt this log fully once everything is resolved? If i put a setTimeout here, it will work fine
console.log(JSON.stringify(hold));
}).catch(console.log)