Skip to content

Commit c35121b

Browse files
pshao25Pan Shao
andauthored
Fix final result check (#36441)
Co-authored-by: Pan Shao <[email protected]>
1 parent b779af6 commit c35121b

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

eng/tools/typespec-migration-validation/src/compare.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HttpMethod, OpenAPI2Document, OpenAPI2Operation, OpenAPI2Response, Ref, Refable } from "@azure-tools/typespec-autorest";
1+
import { HttpMethod, OpenAPI2Document, OpenAPI2Operation, OpenAPI2Response, Refable } from "@azure-tools/typespec-autorest";
22

33
interface Diff {
44
before: any;
@@ -177,23 +177,26 @@ function compareLongRunning(oldOperation: OpenAPI2Operation, newOperation: OpenA
177177
});
178178
}
179179

180-
const newFinalResult = newOperation["x-ms-long-running-operation-options"]?.["final-state-schema"];
181-
if (newFinalResult !== getResponseSchema(oldOperation.responses?.["200"])) {
182-
pathDiffs.push({
183-
before: getResponseSchema(oldOperation.responses?.["200"]),
184-
after: newFinalResult,
185-
operationId: operationId,
186-
type: "finalresult",
187-
level: "error"
188-
});
189-
}
180+
if (oldLongRunning) {
181+
const newFinalResult = newOperation["x-ms-long-running-operation-options"]?.["final-state-schema"];
182+
const newFinalResultSchema = newFinalResult?.split("/").pop();
183+
if (newFinalResultSchema !== getResponseSchema(oldOperation.responses?.["200"])) {
184+
pathDiffs.push({
185+
before: getResponseSchema(oldOperation.responses?.["200"]),
186+
after: newFinalResultSchema,
187+
operationId: operationId,
188+
type: "finalresult",
189+
level: "error"
190+
});
191+
}
192+
}
190193

191194
return pathDiffs;
192195
}
193196

194197
function getResponseSchema(response: Refable<OpenAPI2Response> | undefined): string | undefined {
195-
if (response && (response as Ref<OpenAPI2Response>).$ref) {
196-
const refPath = (response as Ref<OpenAPI2Response>).$ref;
198+
if (response && (response as OpenAPI2Response).schema && ((response as OpenAPI2Response).schema as any).$ref) {
199+
const refPath = ((response as OpenAPI2Response).schema as any).$ref;
197200
return refPath.split("/").pop();
198201
}
199202

eng/tools/typespec-migration-validation/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ export async function main() {
167167
const sortedOldFile = sortOpenAPIDocument(processedOldFile);
168168

169169
logHeader(`Processing new swagger from: ${newPath}...`);
170-
const newFile = readFileContent(newPath!);
171-
const processedNewFile = processDocument(JSON.parse(newFile.toString()));
170+
const newFile = JSON.parse(readFileContent(newPath!).toString());
171+
const processedNewFile = processDocument(newFile);
172172
const sortedNewFile = sortOpenAPIDocument(processedNewFile);
173173

174174
logHeader("Comparing old and new Swagger files...");
@@ -197,8 +197,8 @@ export async function main() {
197197

198198
let outputMarkdown = "";
199199
const compareResult = compareDocuments(
200-
sortedOldFile,
201-
sortedNewFile,
200+
mergedOldfile,
201+
newFile,
202202
);
203203
if (compareResult.length === 0) {
204204
logHeader("No differences found.");

0 commit comments

Comments
 (0)