Skip to content

Commit

Permalink
fix(cli): openapi display names are fixed and we actually validate th… (
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi committed Sep 21, 2024
1 parent 539cfc4 commit c0194d3
Show file tree
Hide file tree
Showing 353 changed files with 1,607 additions and 2,512 deletions.
2 changes: 2 additions & 0 deletions packages/cli/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@fern-api/ir-migrations": "workspace:*",
"@fern-api/ir-sdk": "workspace:*",
"@fern-api/local-workspace-runner": "workspace:*",
"@fern-api/lazy-fern-workspace": "workspace:*",
"@fern-api/logger": "workspace:*",
"@fern-api/logging-execa": "workspace:*",
"@fern-api/login": "workspace:*",
Expand All @@ -69,6 +70,7 @@
"@fern-api/fern-definition-validator": "workspace:*",
"@fern-api/venus-api-sdk": "0.0.38",
"@fern-api/workspace-loader": "workspace:*",
"@fern-api/api-workspace-commons": "workspace:*",
"@fern-api/fern-definition-formatter": "workspace:*",
"@fern-api/cli-migrations": "workspace:*",
"@fern-api/fern-definition-schema": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Logger } from "@fern-api/logger";
import { Project } from "@fern-api/project-loader";
import { isVersionAhead } from "@fern-api/semver-utils";
import { TaskContext } from "@fern-api/task-context";
import { LazyFernWorkspace, OSSWorkspace } from "@fern-api/workspace-loader";
import { AbstractAPIWorkspace } from "@fern-api/workspace-loader";
import { ReleaseType } from "@fern-fern/generators-sdk/api/resources/generators";
import { CliContext } from "../CliContext";

Expand Down Expand Up @@ -134,7 +134,7 @@ async function processGeneratorsYml({
groupFilter
}: {
cliContext: CliContext;
apiWorkspaces: (OSSWorkspace | LazyFernWorkspace)[];
apiWorkspaces: AbstractAPIWorkspace<unknown>[];
perGeneratorAction: (
api: string | undefined,
group: string,
Expand All @@ -149,7 +149,7 @@ async function processGeneratorsYml({
await cliContext.runTaskForWorkspace(workspace, async (context) => {
// If there are no groups in the configuration, skip this workspace
const generatorsConfiguration = await generatorsYml.loadGeneratorsConfiguration({
absolutePathToWorkspace: workspace.absoluteFilepath,
absolutePathToWorkspace: workspace.absoluteFilePath,
context
});
if (generatorsConfiguration == null || generatorsConfiguration.groups == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function addGeneratorToWorkspaces({
await cliContext.runTaskForWorkspace(workspace, async (context) => {
const generatorsConfiguration =
(await generatorsYml.loadRawGeneratorsConfiguration({
absolutePathToWorkspace: workspace.absoluteFilepath,
absolutePathToWorkspace: workspace.absoluteFilePath,
context
})) ?? {};

Expand All @@ -36,7 +36,7 @@ export async function addGeneratorToWorkspaces({
await writeFile(
workspace.generatorsConfiguration?.absolutePathToConfiguration ??
generatorsYml.getPathToGeneratorsConfiguration({
absolutePathToWorkspace: workspace.absoluteFilepath
absolutePathToWorkspace: workspace.absoluteFilePath
}),
yaml.dump(newConfiguration)
);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/cli/src/commands/format/formatWorkspaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Project } from "@fern-api/project-loader";
import { OSSWorkspace } from "@fern-api/workspace-loader";
import { OSSWorkspace } from "@fern-api/lazy-fern-workspace";
import { formatWorkspace } from "@fern-api/fern-definition-formatter";
import { CliContext } from "../../cli-context/CliContext";

Expand All @@ -19,7 +19,7 @@ export async function formatWorkspaces({
}
await cliContext.runTaskForWorkspace(workspace, async (context) => {
await formatWorkspace({
workspace: await workspace.toFernWorkspace({}),
workspace: await workspace.toFernWorkspace({ context }),
context,
shouldFix
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Audiences, generatorsYml } from "@fern-api/configuration";
import { generateIntermediateRepresentation } from "@fern-api/ir-generator";
import { IntermediateRepresentation } from "@fern-api/ir-sdk";
import { TaskContext } from "@fern-api/task-context";
import { FernWorkspace } from "@fern-api/workspace-loader";
import { FernWorkspace } from "@fern-api/api-workspace-commons";
import { validateAPIWorkspaceAndLogIssues } from "../validate/validateAPIWorkspaceAndLogIssues";

export async function generateIrForFernWorkspace({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { migrateIntermediateRepresentationThroughVersion } from "@fern-api/ir-mi
import { serialization as IrSerialization } from "@fern-api/ir-sdk";
import { Project } from "@fern-api/project-loader";
import { TaskContext } from "@fern-api/task-context";
import { FernWorkspace } from "@fern-api/workspace-loader";
import { FernWorkspace } from "@fern-api/api-workspace-commons";
import { writeFile } from "fs/promises";
import path from "path";
import { CliContext } from "../../cli-context/CliContext";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AbsoluteFilePath, stringifyLargeObject } from "@fern-api/fs-utils";
import { serialization } from "@fern-api/openapi-ir-sdk";
import { parse } from "@fern-api/openapi-parser";
import { Project } from "@fern-api/project-loader";
import { getAllOpenAPISpecs, LazyFernWorkspace } from "@fern-api/workspace-loader";
import { getAllOpenAPISpecs, LazyFernWorkspace, OSSWorkspace } from "@fern-api/lazy-fern-workspace";
import { writeFile } from "fs/promises";
import path from "path";
import { CliContext } from "../../cli-context/CliContext";
Expand All @@ -25,10 +25,12 @@ export async function generateOpenAPIIrForWorkspaces({
if (workspace instanceof LazyFernWorkspace) {
context.logger.info("Skipping, API is specified as a Fern Definition.");
return;
} else if (!(workspace instanceof OSSWorkspace)) {
return;
}
const openAPISpecs = await getAllOpenAPISpecs({ context, specs: workspace.specs });
const openAPIIr = await parse({
absoluteFilePathToWorkspace: workspace.absoluteFilepath,
absoluteFilePathToWorkspace: workspace.absoluteFilePath,
specs: openAPISpecs,
taskContext: context
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getEndpointLocation } from "@fern-api/openapi-ir-to-fern";
import { parse } from "@fern-api/openapi-parser";
import { Project } from "@fern-api/project-loader";
import { TaskContext } from "@fern-api/task-context";
import { getAllOpenAPISpecs, OSSWorkspace } from "@fern-api/workspace-loader";
import { getAllOpenAPISpecs, OSSWorkspace } from "@fern-api/lazy-fern-workspace";
import { readFile, writeFile } from "fs/promises";
import yaml from "js-yaml";
import { CliContext } from "../../cli-context/CliContext";
Expand Down Expand Up @@ -62,7 +62,7 @@ async function writeDefinitionForOpenAPIWorkspace({
const specs = await getAllOpenAPISpecs({ context, specs: workspace.specs });
for (const spec of specs) {
const ir = await parse({
absoluteFilePathToWorkspace: workspace.absoluteFilepath,
absoluteFilePathToWorkspace: workspace.absoluteFilePath,
specs: [spec],
taskContext: context
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { runLocalGenerationForWorkspace } from "@fern-api/local-workspace-runner";
import { runRemoteGenerationForAPIWorkspace } from "@fern-api/remote-workspace-runner";
import { TaskContext } from "@fern-api/task-context";
import { APIWorkspace } from "@fern-api/workspace-loader";
import { AbstractAPIWorkspace } from "@fern-api/workspace-loader";
import { GROUP_CLI_OPTION } from "../../constants";
import { validateAPIWorkspaceAndLogIssues } from "../validate/validateAPIWorkspaceAndLogIssues";
import { GenerationMode } from "./generateAPIWorkspaces";
Expand All @@ -28,7 +28,7 @@ export async function generateWorkspace({
mode
}: {
organization: string;
workspace: APIWorkspace;
workspace: AbstractAPIWorkspace<unknown>;
projectConfig: fernConfigJson.ProjectConfig;
context: TaskContext;
version: string | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export async function generateAPIWorkspaces({
project.apiWorkspaces.map(async (workspace) => {
await cliContext.runTaskForWorkspace(workspace, async (context) => {
const absolutePathToPreview = preview
? join(workspace.absoluteFilepath, RelativeFilePath.of(PREVIEW_DIRECTORY))
? join(workspace.absoluteFilePath, RelativeFilePath.of(PREVIEW_DIRECTORY))
: undefined;

if (absolutePathToPreview != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function getGeneratorList({

// If there are no groups in the configuration, skip this workspace
const generatorsConfiguration = await generatorsYml.loadGeneratorsConfiguration({
absolutePathToWorkspace: workspace.absoluteFilepath,
absolutePathToWorkspace: workspace.absoluteFilePath,
context
});
if (generatorsConfiguration == null || generatorsConfiguration.groups == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function getGeneratorMetadata({

// If there are no groups in the configuration, skip this workspace
const generatorsConfiguration = await generatorsYml.loadGeneratorsConfiguration({
absolutePathToWorkspace: workspace.absoluteFilepath,
absolutePathToWorkspace: workspace.absoluteFilePath,
context
});
if (generatorsConfiguration == null || generatorsConfiguration.groups == null) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/cli/src/commands/mock/mockServer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { generateIntermediateRepresentation } from "@fern-api/ir-generator";
import { MockServer } from "@fern-api/mock";
import { Project } from "@fern-api/project-loader";
import { APIWorkspace, FernWorkspace } from "@fern-api/workspace-loader";
import { AbstractAPIWorkspace, FernWorkspace } from "@fern-api/workspace-loader";
import { CliContext } from "../../cli-context/CliContext";
import { API_CLI_OPTION } from "../../constants";
import { validateAPIWorkspaceAndLogIssues } from "../validate/validateAPIWorkspaceAndLogIssues";
Expand All @@ -24,7 +24,7 @@ export async function mockServer({
return cliContext.failAndThrow(`No API specified. Use the --${API_CLI_OPTION} option.`);
}

const workspace: APIWorkspace = project.apiWorkspaces[0];
const workspace: AbstractAPIWorkspace<unknown> = project.apiWorkspaces[0];

await cliContext.runTaskForWorkspace(workspace, async (context) => {
const fernWorkspace: FernWorkspace = await workspace.toFernWorkspace({ context });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createOrganizationIfDoesNotExist, FernToken } from "@fern-api/auth";
import { createFiddleService } from "@fern-api/core";
import { Project } from "@fern-api/project-loader";
import { OSSWorkspace } from "@fern-api/workspace-loader";
import { OSSWorkspace } from "@fern-api/lazy-fern-workspace";
import { YAML_SCHEMA_VERSION } from "@fern-api/fern-definition-schema";
import { FernFiddle } from "@fern-fern/fiddle-sdk";
import axios from "axios";
Expand Down Expand Up @@ -40,7 +40,7 @@ export async function registerWorkspacesV1({
context.failWithoutThrowing("Registering from OpenAPI not currently supported.");
return;
}
const resolvedWorkspace = await workspace.toFernWorkspace({});
const resolvedWorkspace = await workspace.toFernWorkspace({ context });
const registerApiResponse = await fiddle.definitionRegistry.registerUsingOrgToken({
apiId: FernFiddle.ApiId(resolvedWorkspace.definition.rootApiFile.contents.name),
version,
Expand All @@ -63,7 +63,7 @@ export async function registerWorkspacesV1({
const tarPath = path.join(tmpDir.path, "definition.tgz");

context.logger.debug(`Compressing definition at ${tmpDir.path}`);
await tar.create({ file: tarPath, cwd: resolvedWorkspace.absoluteFilepath }, ["."]);
await tar.create({ file: tarPath, cwd: resolvedWorkspace.absoluteFilePath }, ["."]);

context.logger.info("Uploading definition...");
await axios.put(registerApiResponse.body.definitionS3UploadUrl, await readFile(tarPath));
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/cli/src/commands/test/testOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { generateIntermediateRepresentation } from "@fern-api/ir-generator";
import { loggingExeca } from "@fern-api/logging-execa";
import { MockServer } from "@fern-api/mock";
import { Project } from "@fern-api/project-loader";
import { APIWorkspace, FernWorkspace } from "@fern-api/workspace-loader";
import { AbstractAPIWorkspace, FernWorkspace } from "@fern-api/workspace-loader";
import { CliContext } from "../../cli-context/CliContext";
import { API_CLI_OPTION } from "../../constants";
import { validateAPIWorkspaceAndLogIssues } from "../validate/validateAPIWorkspaceAndLogIssues";
Expand Down Expand Up @@ -32,7 +32,7 @@ export async function testOutput({
return cliContext.failAndThrow(`No API specified. Use the --${API_CLI_OPTION} option.`);
}

const workspace: APIWorkspace = project.apiWorkspaces[0];
const workspace: AbstractAPIWorkspace<unknown> = project.apiWorkspaces[0];

await cliContext.runTaskForWorkspace(workspace, async (context) => {
const fernWorkspace: FernWorkspace = await workspace.toFernWorkspace({ context });
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/cli/src/commands/upgrade/updateApiSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function updateApiSpec({
await cliContext.runTaskForWorkspace(workspace, async (context) => {
const generatorConfig =
(await generatorsYml.loadRawGeneratorsConfiguration({
absolutePathToWorkspace: workspace.absoluteFilepath,
absolutePathToWorkspace: workspace.absoluteFilePath,
context
})) ?? {};

Expand All @@ -69,7 +69,7 @@ export async function updateApiSpec({
cliContext.logger.info(`Origin found, fetching spec from ${api.origin}`);
await fetchAndWriteFile(
api.origin,
join(workspace.absoluteFilepath, RelativeFilePath.of(api.path)),
join(workspace.absoluteFilePath, RelativeFilePath.of(api.path)),
cliContext.logger
);
} else if (isPlainObject(api)) {
Expand All @@ -84,7 +84,7 @@ export async function updateApiSpec({
cliContext.logger.info(`Origin found, fetching spec from ${value.origin}`);
await fetchAndWriteFile(
value.origin,
join(workspace.absoluteFilepath, RelativeFilePath.of(value.path)),
join(workspace.absoluteFilePath, RelativeFilePath.of(value.path)),
cliContext.logger
);
}
Expand All @@ -101,7 +101,7 @@ export async function updateApiSpec({
if (origin != null && location != null) {
await fetchAndWriteFile(
origin,
join(workspace.absoluteFilepath, RelativeFilePath.of(location)),
join(workspace.absoluteFilePath, RelativeFilePath.of(location)),
cliContext.logger
);
}
Expand All @@ -120,7 +120,7 @@ export async function updateApiSpec({
cliContext.logger.info(`Origin found, fetching spec from ${apiOrigin}`);
await fetchAndWriteFile(
apiOrigin,
join(workspace.absoluteFilepath, RelativeFilePath.of(apiOutput)),
join(workspace.absoluteFilePath, RelativeFilePath.of(apiOutput)),
cliContext.logger
);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/cli/src/commands/upgrade/upgradeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export async function upgradeGenerator({
// Not totally necessary, but keeping around to ensure the schema is valid
const generatorsConfiguration =
(await generatorsYml.loadRawGeneratorsConfiguration({
absolutePathToWorkspace: workspace.absoluteFilepath,
absolutePathToWorkspace: workspace.absoluteFilePath,
context
})) ?? {};
if (generatorsConfiguration == null || generatorsConfiguration.groups == null) {
Expand All @@ -151,7 +151,7 @@ export async function upgradeGenerator({
context.logger.info(`Upgrading generators in workspace: ${workspace.workspaceName}`);

const updatedConfiguration = await loadAndUpdateGenerators({
absolutePathToWorkspace: workspace.absoluteFilepath,
absolutePathToWorkspace: workspace.absoluteFilePath,
context,
generatorFilter: generator,
groupFilter: group,
Expand All @@ -164,7 +164,7 @@ export async function upgradeGenerator({
await writeFile(
workspace.generatorsConfiguration?.absolutePathToConfiguration ??
generatorsYml.getPathToGeneratorsConfiguration({
absolutePathToWorkspace: workspace.absoluteFilepath
absolutePathToWorkspace: workspace.absoluteFilePath
}),
updatedConfiguration
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TaskContext } from "@fern-api/task-context";
import { validateFernWorkspace } from "@fern-api/fern-definition-validator";
import { FernWorkspace } from "@fern-api/workspace-loader";
import { FernWorkspace } from "@fern-api/api-workspace-commons";
import validatePackageName from "validate-npm-package-name";
import { logViolations } from "./logViolations";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { DEFINITION_DIRECTORY, generatorsYml, ROOT_API_FILENAME } from "@fern-ap
import { AbsoluteFilePath, dirname, doesPathExist, join, RelativeFilePath } from "@fern-api/fs-utils";
import { Project } from "@fern-api/project-loader";
import { TaskContext } from "@fern-api/task-context";
import { FernDefinition, FernWorkspace, OSSWorkspace } from "@fern-api/workspace-loader";
import { FernDefinition, FernWorkspace } from "@fern-api/workspace-loader";
import { OSSWorkspace } from "@fern-api/lazy-fern-workspace";
import chalk from "chalk";
import { mkdir, rmdir, writeFile } from "fs/promises";
import yaml from "js-yaml";
Expand Down Expand Up @@ -40,7 +41,7 @@ async function writeDefinitionForFernWorkspace({
}): Promise<void> {
for (const [relativePath, importedDefinition] of Object.entries(workspace.definition.importedDefinitions)) {
const absolutePathToOutputDirectory = join(
workspace.absoluteFilepath,
workspace.absoluteFilePath,
RelativeFilePath.of(DEFINITION_DIRECTORY),
RelativeFilePath.of(relativePath),
RelativeFilePath.of(`.${DEFINITION_DIRECTORY}`)
Expand All @@ -66,7 +67,7 @@ async function writeDefinitionForOpenAPIWorkspace({
}): Promise<void> {
const fernWorkspace = await workspace.toFernWorkspace({ context });
const absolutePathToOutputDirectory = join(
workspace.absoluteFilepath,
workspace.absoluteFilePath,
RelativeFilePath.of(`.${DEFINITION_DIRECTORY}`)
);
await writeFernDefinition({
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
{ "path": "../semver-utils" },
{ "path": "../task-context" },
{ "path": "../workspace-loader" },
{ "path": "../workspace-commons" },
{ "path": "../lazy-fern-workspace" },
{ "path": "../yaml/docs-validator" },
{ "path": "../fern-definition/formatter" },
{ "path": "../fern-definition/validator" },
Expand Down
Loading

0 comments on commit c0194d3

Please sign in to comment.