Skip to content

Commit

Permalink
fix: api update command now works with unioned + nested APIs (#3944)
Browse files Browse the repository at this point in the history
  • Loading branch information
armandobelardo authored Jun 27, 2024
1 parent ddf99a5 commit 663e2fe
Show file tree
Hide file tree
Showing 13 changed files with 3,078 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packages/cli/cli/src/commands/upgrade/updateApiSpec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { generatorsYml, getFernDirectory } from "@fern-api/configuration";
import { join, RelativeFilePath } from "@fern-api/fs-utils";
import { Logger } from "@fern-api/logger";
import { Project } from "@fern-api/project-loader";
import * as fs from "fs";
import { readFile, writeFile } from "fs/promises";
import yaml from "js-yaml";
import path from "path";
import { Readable } from "stream";
import { finished } from "stream/promises";
import { ReadableStream } from "stream/web";
Expand Down Expand Up @@ -63,7 +63,11 @@ export async function updateApiSpec({
for (const api of apis) {
if (typeof api !== "string" && api.origin != null) {
cliContext.logger.info(`Origin found, fetching spec from ${api.origin}`);
await fetchAndWriteFile(api.origin, path.join(fernDirectory, api.path), cliContext.logger);
await fetchAndWriteFile(
api.origin,
join(workspace.absoluteFilepath, RelativeFilePath.of(api.path)),
cliContext.logger
);
}
}
} else if (generatorConfig[generatorsYml.ASYNC_API_LOCATION_KEY] != null) {
Expand All @@ -74,7 +78,11 @@ export async function updateApiSpec({
const origin = generatorConfig[generatorsYml.API_ORIGIN_LOCATION_KEY];
const location = generatorConfig[generatorsYml.ASYNC_API_LOCATION_KEY];
if (origin != null && location != null) {
await fetchAndWriteFile(origin, path.join(fernDirectory, location), cliContext.logger);
await fetchAndWriteFile(
origin,
join(workspace.absoluteFilepath, RelativeFilePath.of(location)),
cliContext.logger
);
}
}
} else if (generatorConfig[generatorsYml.OPENAPI_LOCATION_KEY] != null) {
Expand All @@ -89,7 +97,11 @@ export async function updateApiSpec({
if (apiOrigin != null && apiOutput != null) {
origin = apiOrigin;
cliContext.logger.info(`Origin found, fetching spec from ${apiOrigin}`);
await fetchAndWriteFile(apiOrigin, path.join(fernDirectory, apiOutput), cliContext.logger);
await fetchAndWriteFile(
apiOrigin,
join(workspace.absoluteFilepath, RelativeFilePath.of(apiOutput)),
cliContext.logger
);
}
}
return;
Expand Down
Loading

0 comments on commit 663e2fe

Please sign in to comment.