mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-25 12:54:09 +02:00
fix(openapi): import server environments
This commit is contained in:
@@ -301,8 +301,70 @@ describe("importer-openapi", () => {
|
||||
|
||||
expect(imported?.resources.httpRequests.map((r) => r.url)).toEqual([
|
||||
"${[baseUrl]}/root",
|
||||
"https://path.example.com/path-level",
|
||||
"https://operation.example.com/operation-level",
|
||||
"${[serverUrl]}/path-level",
|
||||
"${[serverUrl2]}/operation-level",
|
||||
]);
|
||||
expect(imported?.resources.environments[0]?.variables).toEqual([
|
||||
{ name: "baseUrl", value: "https://root.example.com" },
|
||||
{ name: "serverUrl", value: "https://path.example.com" },
|
||||
{ name: "serverUrl2", value: "https://operation.example.com" },
|
||||
]);
|
||||
});
|
||||
|
||||
test("Creates selectable environments for multiple OpenAPI servers", async () => {
|
||||
const imported = await convertOpenApi(
|
||||
JSON.stringify({
|
||||
openapi: "3.0.4",
|
||||
info: { title: "Server Environments Test", version: "1.0.0" },
|
||||
servers: [
|
||||
{ url: "https://api.example.com/v1", description: "Production" },
|
||||
{ url: "https://sandbox.example.com/v1", description: "Sandbox" },
|
||||
],
|
||||
paths: { "/items": { get: { responses: {} } } },
|
||||
}),
|
||||
);
|
||||
|
||||
expect(imported?.resources.environments).toEqual([
|
||||
expect.objectContaining({
|
||||
name: "Global Variables",
|
||||
variables: [{ name: "baseUrl", value: "https://api.example.com/v1" }],
|
||||
}),
|
||||
expect.objectContaining({
|
||||
name: "Production",
|
||||
parentModel: "environment",
|
||||
variables: [{ name: "baseUrl", value: "https://api.example.com/v1" }],
|
||||
}),
|
||||
expect.objectContaining({
|
||||
name: "Sandbox",
|
||||
parentModel: "environment",
|
||||
variables: [{ name: "baseUrl", value: "https://sandbox.example.com/v1" }],
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
test("Creates variables for path servers without a top-level server", async () => {
|
||||
const imported = await convertOpenApi(
|
||||
JSON.stringify({
|
||||
openapi: "3.0.4",
|
||||
info: { title: "Path Server Test", version: "1.0.0" },
|
||||
paths: {
|
||||
"/items": {
|
||||
servers: [{ url: "https://path.example.com" }],
|
||||
get: { responses: {} },
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(imported?.resources.httpRequests[0]?.url).toBe("${[serverUrl]}/items");
|
||||
expect(imported?.resources.environments).toEqual([
|
||||
expect.objectContaining({
|
||||
name: "Global Variables",
|
||||
variables: [
|
||||
{ name: "baseUrl", value: "" },
|
||||
{ name: "serverUrl", value: "https://path.example.com" },
|
||||
],
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user