Skip to content

Commit 726cb7a

Browse files
committed
chore: fix downloading error
1 parent 0e587eb commit 726cb7a

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/generator/download.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,19 @@ export async function downloadDiscoveryDocs(
8686
const url = `${options.discoveryUrl}/${api.name}.${api.version}.json`;
8787
const changeSet: ChangeSet = {api, changes: []};
8888
try {
89-
const res = await request<{}>({url});
89+
const res = await request({url});
9090
// The keys in the downloaded JSON come back in an arbitrary order from
9191
// request to request. Sort them before storing.
92-
const newDoc = sortKeys(res.data);
92+
// console.log(JSON.parse(res.data as string))
93+
const newDoc = sortKeys(JSON.parse(res.data as string));
9394
let updateFile = true;
9495

9596
try {
9697
const oldDoc = JSON.parse(await gfs.readFile(apiPath));
98+
// console.log(oldDoc)
99+
// console.log(newDoc)
97100
updateFile = shouldUpdate(newDoc, oldDoc);
101+
// console.log(updateFile)
98102
changeSet.changes = getDiffs(oldDoc, newDoc);
99103
} catch {
100104
// If the file doesn't exist, that's fine it's just new

src/generator/generator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class Generator {
109109
if (useCache) {
110110
console.log('Reading from cache...');
111111
} else {
112-
changes = await downloadDiscoveryDocs({
112+
changes = await downloadDiscoveryDocs({
113113
includePrivate: this.options.includePrivate,
114114
discoveryUrl,
115115
downloadPath: discoveryPath,
@@ -133,6 +133,8 @@ export class Generator {
133133
api.discoveryRestUrl,
134134
'Attempting first generateAPI call...'
135135
);
136+
console.log("DISCOVERY PATH")
137+
console.log(discoveryPath)
136138
try {
137139
const apiPath = path.join(
138140
discoveryPath,

test/test.download.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe(__filename, () => {
7878
assert.strictEqual(shouldUpdate, false);
7979
});
8080

81-
it('should download the discovery docs', async () => {
81+
it.only('should download the discovery docs', async () => {
8282
const scopes = [
8383
nock(
8484
'https://raw.githubusercontent.com/googleapis/discovery-artifact-manager/master/discoveries'
@@ -91,7 +91,10 @@ describe(__filename, () => {
9191
'https://raw.githubusercontent.com/googleapis/discovery-artifact-manager/master/discoveries'
9292
)
9393
.get('/fake.v1.json')
94-
.reply(200),
94+
.reply(
95+
200,
96+
'{"id": "fake:v1","discoveryRestUrl": "http://localhost:3030/path","name": "fake","version": "v1"}'
97+
),
9598
];
9699
const mkdirpStub = sandbox.stub(dn.gfs, 'mkdir').resolves();
97100
const writeFileStub = sandbox.stub(dn.gfs, 'writeFile');
@@ -117,9 +120,10 @@ describe(__filename, () => {
117120
'https://raw.githubusercontent.com/googleapis/discovery-artifact-manager/master/discoveries'
118121
)
119122
.get('/fake.v1.json')
120-
.reply(200, {
121-
revision: '1234',
122-
}),
123+
.reply(
124+
200,
125+
'{"id": "fake:v1","discoveryRestUrl": "http://localhost:3030/path","name": "fake","version": "v1", revision: "1234"}'
126+
),
123127
];
124128
const writeFileStub = sandbox.stub(dn.gfs, 'writeFile');
125129
const readFileStub = sandbox.stub(dn.gfs, 'readFile').callsFake(() => {

0 commit comments

Comments
 (0)