Skip to content

Commit

Permalink
Fixes #9498.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott committed Jan 8, 2025
1 parent e345b1d commit 517d7e0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 207 deletions.
205 changes: 7 additions & 198 deletions tools/tsp-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tools/tsp-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"dependencies": {
"@autorest/core": "^3.10.2",
"@autorest/openapi-to-typespec": "0.10.5",
"@azure-tools/rest-api-diff": ">=0.1.0 <1.0.0",
"@azure-tools/rest-api-diff": "^0.1.8",
"@azure-tools/typespec-autorest": ">=0.44.0 <1.0.0",
"@azure/core-rest-pipeline": "^1.12.0",
"@types/yargs": "^17.0.32",
Expand Down
21 changes: 14 additions & 7 deletions tools/tsp-client/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { config as dotenvConfig } from "dotenv";
import { resolve } from "node:path";
import { doesFileExist } from "./network.js";
import { sortOpenAPIDocument } from "@azure-tools/typespec-autorest";
import { execSync } from "child_process";

export async function initCommand(argv: any) {
let outputDir = argv["output-dir"];
Expand Down Expand Up @@ -311,13 +312,19 @@ export async function generateCommand(argv: any) {

export async function compareCommand(argv: any, args: string[]) {
let outputDir = argv["output-dir"];
const openApiDiffPath = await getPathToDependency("@azure-tools/rest-api-diff");
const command = [openApiDiffPath, ...args];
try {
await nodeCommand(outputDir, command);
} catch (err) {
Logger.error(`Error occurred while attempting to compare: ${err}`);
process.exit(1);
if (argv["update"]) {
execSync(`npm install @azure-tools/rest-api-diff@latest`, { stdio: "inherit" });
Logger.info("Updated @azure-tools/rest-api-diff to the latest version");
} else {
const openApiDiffPath = await getPathToDependency("@azure-tools/rest-api-diff");
const command = [openApiDiffPath, ...args];
try {
await nodeCommand(outputDir, command);
Logger.info("Use `tsp-client compare --update` to update @azure-tools/rest-api-diff to the latest version");
} catch (err) {
Logger.error(`Error occurred while attempting to compare: ${err}`);
process.exit(1);
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion tools/tsp-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ const parser = yargs(hideBin(process.argv))
"compare",
"Compare two Swaggers for functional equivalency. This is typically used to compare a source Swagger with a TypeSpec project or TypeSpec generated Swagger to ensure that the TypeSpec project is functionally equivalent to the source Swagger.",
(yargs: any) => {
return yargs.help(false);
return yargs
.option("update", {
type: "boolean",
description: "Update `@azure-tools/rest-api-diff` to the latest version.",
default: false,
})
.help(false);
},
async (argv: any) => {
argv["output-dir"] = resolveOutputDir(argv);
Expand Down

0 comments on commit 517d7e0

Please sign in to comment.