Skip to content

Commit 358c264

Browse files
committed
Add tsp-client compare command.
1 parent 0251b70 commit 358c264

4 files changed

Lines changed: 25 additions & 14 deletions

File tree

tools/tsp-client/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ node_modules
33
dist
44
types
55
temp
6+
tsp-output/
7+
output/

tools/tsp-client/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Added `generate-lock-file` command, see [README](https://github.com/Azure/azure-sdk-tools/blob/main/tools/tsp-client/README.md) for more information.
66
- Removed the `--generate-lock-file` flag and replaced it with the command above.
77
- Migrated tsp-client from `node:util` to `yargs` for commandline infrastructure.
8+
- Added `compare` command to compare a hand-authored Swagger to a TypeSpec-generated Swagger to understand the relevant differences between them.
89

910
## 2024-08-05 - 0.10.0
1011

tools/tsp-client/src/commands.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,16 @@ export async function generateCommand(argv: any) {
284284
}
285285
}
286286

287-
export async function compareCommand(argv: any) {
288-
// TODO: Implement
287+
export async function compareCommand(argv: any, args: string[]) {
288+
let outputDir = argv["output-dir"];
289+
const openApiDiffPath = await getPathToDependency("openapi-diff");
290+
const command = [openApiDiffPath, ...args];
291+
try {
292+
await nodeCommand(outputDir, command);
293+
} catch (err) {
294+
Logger.error(`Error occurred while attempting to compare: ${err}`);
295+
process.exit(1);
296+
}
289297
}
290298

291299
export async function updateCommand(argv: any) {

tools/tsp-client/src/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,6 @@ const parser = yargs(hideBin(process.argv))
142142
await generateCommand(argv);
143143
},
144144
)
145-
.command(
146-
"compare",
147-
"Compare two Swaggers for functional equivalency. This is typically used to compare a source Swagger with a TypeSpec-generated Swagger to ensure that the TypeSpec project is functionally equivalent to the source Swagger.",
148-
(yargs: any) => {
149-
// FIXME: Add options
150-
return yargs;
151-
},
152-
async (argv: any) => {
153-
argv["output-dir"] = resolveOutputDir(argv);
154-
await compareCommand(argv);
155-
},
156-
)
157145
.command(
158146
"update",
159147
"Sync and generate from a TypeSpec project",
@@ -231,6 +219,18 @@ const parser = yargs(hideBin(process.argv))
231219
await sortSwaggerCommand(argv);
232220
},
233221
)
222+
.command(
223+
"compare",
224+
"Compare two Swaggers for functional equivalency. This is typically used to compare a source Swagger with a TypeSpec-generated Swagger to ensure that the TypeSpec project is functionally equivalent to the source Swagger.",
225+
(yargs: any) => {
226+
return yargs.help(false);
227+
},
228+
async (argv: any) => {
229+
argv["output-dir"] = resolveOutputDir(argv);
230+
const rawArgs = process.argv.slice(3);
231+
await compareCommand(argv, rawArgs);
232+
},
233+
)
234234
.demandCommand(1, "Please provide a command.")
235235
.help()
236236
.showHelpOnFail(true);

0 commit comments

Comments
 (0)