mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-09-08 10:51:59 +02:00
feat(import): add stable per-resource source keys to the importer contract (#614)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
e63a87718c
commit
81a2a5d955
@@ -308,6 +308,16 @@ License: CC0 1.0 (https://github.com/APIs-guru/openapi-directory#licenses)",
|
||||
},
|
||||
],
|
||||
},
|
||||
"sourceKeys": {
|
||||
"GENERATE_ID::FOLDER_0": "tag:APIs",
|
||||
"GENERATE_ID::HTTP_REQUEST_0": "op:listAPIs",
|
||||
"GENERATE_ID::HTTP_REQUEST_1": "op:getMetrics",
|
||||
"GENERATE_ID::HTTP_REQUEST_2": "op:getProviders",
|
||||
"GENERATE_ID::HTTP_REQUEST_3": "op:getAPI",
|
||||
"GENERATE_ID::HTTP_REQUEST_4": "op:getServiceAPI",
|
||||
"GENERATE_ID::HTTP_REQUEST_5": "op:getProvider",
|
||||
"GENERATE_ID::HTTP_REQUEST_6": "op:getServices",
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -2600,6 +2610,97 @@ Contact: me@kennethreitz.org",
|
||||
},
|
||||
],
|
||||
},
|
||||
"sourceKeys": {
|
||||
"GENERATE_ID::FOLDER_0": "tag:HTTP Methods",
|
||||
"GENERATE_ID::FOLDER_1": "tag:Auth",
|
||||
"GENERATE_ID::FOLDER_10": "tag:Anything",
|
||||
"GENERATE_ID::FOLDER_2": "tag:Status codes",
|
||||
"GENERATE_ID::FOLDER_3": "tag:Request inspection",
|
||||
"GENERATE_ID::FOLDER_4": "tag:Response inspection",
|
||||
"GENERATE_ID::FOLDER_5": "tag:Response formats",
|
||||
"GENERATE_ID::FOLDER_6": "tag:Dynamic data",
|
||||
"GENERATE_ID::FOLDER_7": "tag:Cookies",
|
||||
"GENERATE_ID::FOLDER_8": "tag:Images",
|
||||
"GENERATE_ID::FOLDER_9": "tag:Redirects",
|
||||
"GENERATE_ID::HTTP_REQUEST_0": "route:GET /absolute-redirect/{n}",
|
||||
"GENERATE_ID::HTTP_REQUEST_1": "route:DELETE /anything",
|
||||
"GENERATE_ID::HTTP_REQUEST_10": "route:POST /anything/{anything}",
|
||||
"GENERATE_ID::HTTP_REQUEST_11": "route:PUT /anything/{anything}",
|
||||
"GENERATE_ID::HTTP_REQUEST_12": "route:TRACE /anything/{anything}",
|
||||
"GENERATE_ID::HTTP_REQUEST_13": "route:GET /base64/{value}",
|
||||
"GENERATE_ID::HTTP_REQUEST_14": "route:GET /basic-auth/{user}/{passwd}",
|
||||
"GENERATE_ID::HTTP_REQUEST_15": "route:GET /bearer",
|
||||
"GENERATE_ID::HTTP_REQUEST_16": "route:GET /brotli",
|
||||
"GENERATE_ID::HTTP_REQUEST_17": "route:GET /bytes/{n}",
|
||||
"GENERATE_ID::HTTP_REQUEST_18": "route:GET /cache",
|
||||
"GENERATE_ID::HTTP_REQUEST_19": "route:GET /cache/{value}",
|
||||
"GENERATE_ID::HTTP_REQUEST_2": "route:GET /anything",
|
||||
"GENERATE_ID::HTTP_REQUEST_20": "route:GET /cookies",
|
||||
"GENERATE_ID::HTTP_REQUEST_21": "route:GET /cookies/delete",
|
||||
"GENERATE_ID::HTTP_REQUEST_22": "route:GET /cookies/set",
|
||||
"GENERATE_ID::HTTP_REQUEST_23": "route:GET /cookies/set/{name}/{value}",
|
||||
"GENERATE_ID::HTTP_REQUEST_24": "route:GET /deflate",
|
||||
"GENERATE_ID::HTTP_REQUEST_25": "route:DELETE /delay/{delay}",
|
||||
"GENERATE_ID::HTTP_REQUEST_26": "route:GET /delay/{delay}",
|
||||
"GENERATE_ID::HTTP_REQUEST_27": "route:PATCH /delay/{delay}",
|
||||
"GENERATE_ID::HTTP_REQUEST_28": "route:POST /delay/{delay}",
|
||||
"GENERATE_ID::HTTP_REQUEST_29": "route:PUT /delay/{delay}",
|
||||
"GENERATE_ID::HTTP_REQUEST_3": "route:PATCH /anything",
|
||||
"GENERATE_ID::HTTP_REQUEST_30": "route:TRACE /delay/{delay}",
|
||||
"GENERATE_ID::HTTP_REQUEST_31": "route:DELETE /delete",
|
||||
"GENERATE_ID::HTTP_REQUEST_32": "route:GET /deny",
|
||||
"GENERATE_ID::HTTP_REQUEST_33": "route:GET /digest-auth/{qop}/{user}/{passwd}",
|
||||
"GENERATE_ID::HTTP_REQUEST_34": "route:GET /digest-auth/{qop}/{user}/{passwd}/{algorithm}",
|
||||
"GENERATE_ID::HTTP_REQUEST_35": "route:GET /digest-auth/{qop}/{user}/{passwd}/{algorithm}/{stale_after}",
|
||||
"GENERATE_ID::HTTP_REQUEST_36": "route:GET /drip",
|
||||
"GENERATE_ID::HTTP_REQUEST_37": "route:GET /encoding/utf8",
|
||||
"GENERATE_ID::HTTP_REQUEST_38": "route:GET /etag/{etag}",
|
||||
"GENERATE_ID::HTTP_REQUEST_39": "route:GET /get",
|
||||
"GENERATE_ID::HTTP_REQUEST_4": "route:POST /anything",
|
||||
"GENERATE_ID::HTTP_REQUEST_40": "route:GET /gzip",
|
||||
"GENERATE_ID::HTTP_REQUEST_41": "route:GET /headers",
|
||||
"GENERATE_ID::HTTP_REQUEST_42": "route:GET /hidden-basic-auth/{user}/{passwd}",
|
||||
"GENERATE_ID::HTTP_REQUEST_43": "route:GET /html",
|
||||
"GENERATE_ID::HTTP_REQUEST_44": "route:GET /image",
|
||||
"GENERATE_ID::HTTP_REQUEST_45": "route:GET /image/jpeg",
|
||||
"GENERATE_ID::HTTP_REQUEST_46": "route:GET /image/png",
|
||||
"GENERATE_ID::HTTP_REQUEST_47": "route:GET /image/svg",
|
||||
"GENERATE_ID::HTTP_REQUEST_48": "route:GET /image/webp",
|
||||
"GENERATE_ID::HTTP_REQUEST_49": "route:GET /ip",
|
||||
"GENERATE_ID::HTTP_REQUEST_5": "route:PUT /anything",
|
||||
"GENERATE_ID::HTTP_REQUEST_50": "route:GET /json",
|
||||
"GENERATE_ID::HTTP_REQUEST_51": "route:GET /links/{n}/{offset}",
|
||||
"GENERATE_ID::HTTP_REQUEST_52": "route:PATCH /patch",
|
||||
"GENERATE_ID::HTTP_REQUEST_53": "route:POST /post",
|
||||
"GENERATE_ID::HTTP_REQUEST_54": "route:PUT /put",
|
||||
"GENERATE_ID::HTTP_REQUEST_55": "route:GET /range/{numbytes}",
|
||||
"GENERATE_ID::HTTP_REQUEST_56": "route:DELETE /redirect-to",
|
||||
"GENERATE_ID::HTTP_REQUEST_57": "route:GET /redirect-to",
|
||||
"GENERATE_ID::HTTP_REQUEST_58": "route:PATCH /redirect-to",
|
||||
"GENERATE_ID::HTTP_REQUEST_59": "route:POST /redirect-to",
|
||||
"GENERATE_ID::HTTP_REQUEST_6": "route:TRACE /anything",
|
||||
"GENERATE_ID::HTTP_REQUEST_60": "route:PUT /redirect-to",
|
||||
"GENERATE_ID::HTTP_REQUEST_61": "route:TRACE /redirect-to",
|
||||
"GENERATE_ID::HTTP_REQUEST_62": "route:GET /redirect/{n}",
|
||||
"GENERATE_ID::HTTP_REQUEST_63": "route:GET /relative-redirect/{n}",
|
||||
"GENERATE_ID::HTTP_REQUEST_64": "route:GET /response-headers",
|
||||
"GENERATE_ID::HTTP_REQUEST_65": "route:POST /response-headers",
|
||||
"GENERATE_ID::HTTP_REQUEST_66": "route:GET /robots.txt",
|
||||
"GENERATE_ID::HTTP_REQUEST_67": "route:DELETE /status/{codes}",
|
||||
"GENERATE_ID::HTTP_REQUEST_68": "route:GET /status/{codes}",
|
||||
"GENERATE_ID::HTTP_REQUEST_69": "route:PATCH /status/{codes}",
|
||||
"GENERATE_ID::HTTP_REQUEST_7": "route:DELETE /anything/{anything}",
|
||||
"GENERATE_ID::HTTP_REQUEST_70": "route:POST /status/{codes}",
|
||||
"GENERATE_ID::HTTP_REQUEST_71": "route:PUT /status/{codes}",
|
||||
"GENERATE_ID::HTTP_REQUEST_72": "route:TRACE /status/{codes}",
|
||||
"GENERATE_ID::HTTP_REQUEST_73": "route:GET /stream-bytes/{n}",
|
||||
"GENERATE_ID::HTTP_REQUEST_74": "route:GET /stream/{n}",
|
||||
"GENERATE_ID::HTTP_REQUEST_75": "route:GET /user-agent",
|
||||
"GENERATE_ID::HTTP_REQUEST_76": "route:GET /uuid",
|
||||
"GENERATE_ID::HTTP_REQUEST_77": "route:GET /xml",
|
||||
"GENERATE_ID::HTTP_REQUEST_8": "route:GET /anything/{anything}",
|
||||
"GENERATE_ID::HTTP_REQUEST_9": "route:PATCH /anything/{anything}",
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -2734,6 +2835,10 @@ License: Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html)",
|
||||
},
|
||||
],
|
||||
},
|
||||
"sourceKeys": {
|
||||
"GENERATE_ID::FOLDER_0": "tag:request tag",
|
||||
"GENERATE_ID::HTTP_REQUEST_0": "route:GET /apod",
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -2834,5 +2939,9 @@ Responses:
|
||||
},
|
||||
],
|
||||
},
|
||||
"sourceKeys": {
|
||||
"GENERATE_ID::HTTP_REQUEST_0": "route:GET /info.0.json",
|
||||
"GENERATE_ID::HTTP_REQUEST_1": "route:GET /{comicId}/info.0.json",
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -2382,4 +2382,38 @@ describe("importer-openapi", () => {
|
||||
expect(imported).toMatchSnapshot();
|
||||
});
|
||||
}
|
||||
|
||||
test("Keys operations by operationId, unchanged by a rename", async () => {
|
||||
const spec = (summary: string) =>
|
||||
JSON.stringify({
|
||||
openapi: "3.0.0",
|
||||
info: { title: "Keys", version: "1" },
|
||||
paths: {
|
||||
"/pets": {
|
||||
get: { operationId: "listPets", summary, tags: ["pets"], responses: {} },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const before = await convertOpenApi(spec("List pets"));
|
||||
const after = await convertOpenApi(spec("Fetch every pet"));
|
||||
|
||||
expect(before?.sourceKeys?.[before.resources.httpRequests[0]!.id]).toBe("op:listPets");
|
||||
expect(after?.sourceKeys?.[after.resources.httpRequests[0]!.id]).toBe("op:listPets");
|
||||
expect(before?.sourceKeys?.[before.resources.folders[0]!.id]).toBe("tag:pets");
|
||||
});
|
||||
|
||||
test("Falls back to the route when an operation has no operationId", async () => {
|
||||
const imported = await convertOpenApi(
|
||||
JSON.stringify({
|
||||
openapi: "3.0.0",
|
||||
info: { title: "Keys", version: "1" },
|
||||
paths: { "/pets/{id}": { delete: { summary: "Remove", responses: {} } } },
|
||||
}),
|
||||
);
|
||||
|
||||
expect(imported?.sourceKeys?.[imported.resources.httpRequests[0]!.id]).toBe(
|
||||
"route:DELETE /pets/{id}",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user