Skip to content

Commit 3555cdd

Browse files
committed
[compile.ts] Use Swagger
1 parent cbbaa99 commit 3555cdd

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

eng/tools/typespec-validation/src/rules/compile.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { filterAsync } from "@azure-tools/specs-shared/array";
2-
import { readFile } from "fs/promises";
2+
import { defaultLogger } from "@azure-tools/specs-shared/logger";
3+
import { Swagger } from "@azure-tools/specs-shared/swagger";
34
import { globby } from "globby";
45
import path, { basename, dirname, normalize } from "path";
56
import pc from "picocolors";
@@ -103,12 +104,8 @@ export class CompileRule implements Rule {
103104
const tspGeneratedSwaggers = await filterAsync(
104105
allSwaggers,
105106
async (swaggerPath: string) => {
106-
const swaggerText = await readFile(swaggerPath, { encoding: "utf8" });
107-
const swaggerObj = JSON.parse(swaggerText);
108-
return (
109-
swaggerObj["info"]?.["x-typespec-generated"] ||
110-
swaggerObj["info"]?.["x-cadl-generated"]
111-
);
107+
const swagger = new Swagger(swaggerPath, { logger: defaultLogger });
108+
return (await swagger.getTypeSpecGenerated()) || (await swagger.getCadlGenerated());
112109
},
113110
);
114111

@@ -178,7 +175,7 @@ export class CompileRule implements Rule {
178175

179176
const clientTsp = path.join(folder, "client.tsp");
180177
if (await fileExists(clientTsp)) {
181-
let [err, stdout, stderr] = await runNpm([
178+
const [err, stdout, stderr] = await runNpm([
182179
"exec",
183180
"--no",
184181
"--",

0 commit comments

Comments
 (0)