mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-25 12:54:09 +02:00
Feed numeric Swagger versions into server detection
This commit is contained in:
@@ -481,11 +481,12 @@ function parseSpec(contents: string): unknown {
|
|||||||
function isOpenApiSpec(value: unknown): value is UnknownRecord {
|
function isOpenApiSpec(value: unknown): value is UnknownRecord {
|
||||||
const spec = toRecord(value);
|
const spec = toRecord(value);
|
||||||
const openapi = versionString(spec.openapi);
|
const openapi = versionString(spec.openapi);
|
||||||
|
return isRecord(spec.paths) && (/^3(\.|$)/.test(openapi ?? "") || isSwagger2(spec));
|
||||||
|
}
|
||||||
|
|
||||||
|
function isSwagger2(spec: UnknownRecord): boolean {
|
||||||
const swagger = versionString(spec.swagger);
|
const swagger = versionString(spec.swagger);
|
||||||
return (
|
return swagger === "2.0" || swagger === "2";
|
||||||
isRecord(spec.paths) &&
|
|
||||||
(/^3(\.|$)/.test(openapi ?? "") || swagger === "2.0" || swagger === "2")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function versionString(value: unknown): string | undefined {
|
function versionString(value: unknown): string | undefined {
|
||||||
@@ -713,8 +714,7 @@ function importServerEnvironments(spec: UnknownRecord): { name: string; url: str
|
|||||||
.filter(({ url }) => url.length > 0);
|
.filter(({ url }) => url.length > 0);
|
||||||
if (servers.length === 0) {
|
if (servers.length === 0) {
|
||||||
const hasSwaggerServer =
|
const hasSwaggerServer =
|
||||||
stringAt(spec, "swagger") === "2.0" &&
|
isSwagger2(spec) && (stringAt(spec, "host") != null || stringAt(spec, "basePath") != null);
|
||||||
(stringAt(spec, "host") != null || stringAt(spec, "basePath") != null);
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
name: hasSwaggerServer ? "Server 1" : "Default",
|
name: hasSwaggerServer ? "Server 1" : "Default",
|
||||||
|
|||||||
@@ -1251,6 +1251,14 @@ describe("importer-openapi", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(imported?.resources.httpRequests[0]?.url).toBe("${[baseUrl]}/a");
|
expect(imported?.resources.httpRequests[0]?.url).toBe("${[baseUrl]}/a");
|
||||||
|
// The numeric version must feed server detection too, or the selectable
|
||||||
|
// environment overrides baseUrl with an empty value
|
||||||
|
expect(imported?.resources.environments[1]).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
name: "Server 1",
|
||||||
|
variables: [{ name: "baseUrl", value: "https://example.com" }],
|
||||||
|
}),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Normalizes body types to Yaak's editors", async () => {
|
test("Normalizes body types to Yaak's editors", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user