mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-24 09:38:29 +02:00
Fix [object Object] request descriptions after OpenAPI import (#412)
This commit is contained in:
@@ -7,6 +7,29 @@ describe('importer-openapi', () => {
|
|||||||
const p = path.join(__dirname, 'fixtures');
|
const p = path.join(__dirname, 'fixtures');
|
||||||
const fixtures = fs.readdirSync(p);
|
const fixtures = fs.readdirSync(p);
|
||||||
|
|
||||||
|
test('Maps operation description to request description', async () => {
|
||||||
|
const imported = await convertOpenApi(
|
||||||
|
JSON.stringify({
|
||||||
|
openapi: '3.0.0',
|
||||||
|
info: { title: 'Description Test', version: '1.0.0' },
|
||||||
|
paths: {
|
||||||
|
'/klanten': {
|
||||||
|
get: {
|
||||||
|
description: 'Lijst van klanten',
|
||||||
|
responses: { '200': { description: 'ok' } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(imported?.resources.httpRequests).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
description: 'Lijst van klanten',
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
test('Skips invalid file', async () => {
|
test('Skips invalid file', async () => {
|
||||||
const imported = await convertOpenApi('{}');
|
const imported = await convertOpenApi('{}');
|
||||||
expect(imported).toBeUndefined();
|
expect(imported).toBeUndefined();
|
||||||
|
|||||||
@@ -55,19 +55,11 @@ export function convertPostman(contents: string): ImportPluginResponse | undefin
|
|||||||
folders: [],
|
folders: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const rawDescription = info.description;
|
|
||||||
const description =
|
|
||||||
typeof rawDescription === 'object' && rawDescription != null && 'content' in rawDescription
|
|
||||||
? String(rawDescription.content)
|
|
||||||
: rawDescription == null
|
|
||||||
? undefined
|
|
||||||
: String(rawDescription);
|
|
||||||
|
|
||||||
const workspace: ExportResources['workspaces'][0] = {
|
const workspace: ExportResources['workspaces'][0] = {
|
||||||
model: 'workspace',
|
model: 'workspace',
|
||||||
id: generateId('workspace'),
|
id: generateId('workspace'),
|
||||||
name: info.name ? String(info.name) : 'Postman Import',
|
name: info.name ? String(info.name) : 'Postman Import',
|
||||||
description,
|
description: importDescription(info.description),
|
||||||
...globalAuth,
|
...globalAuth,
|
||||||
};
|
};
|
||||||
exportResources.workspaces.push(workspace);
|
exportResources.workspaces.push(workspace);
|
||||||
@@ -139,7 +131,7 @@ export function convertPostman(contents: string): ImportPluginResponse | undefin
|
|||||||
workspaceId: workspace.id,
|
workspaceId: workspace.id,
|
||||||
folderId,
|
folderId,
|
||||||
name: v.name,
|
name: v.name,
|
||||||
description: r.description ? String(r.description) : undefined,
|
description: importDescription(r.description),
|
||||||
method: typeof r.method === 'string' ? r.method : 'GET',
|
method: typeof r.method === 'string' ? r.method : 'GET',
|
||||||
url,
|
url,
|
||||||
urlParameters,
|
urlParameters,
|
||||||
@@ -509,6 +501,26 @@ function toArray<T>(value: unknown): T[] {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function importDescription(rawDescription: unknown): string | undefined {
|
||||||
|
if (rawDescription == null) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof rawDescription === 'string') {
|
||||||
|
return rawDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof rawDescription === 'object' && !Array.isArray(rawDescription)) {
|
||||||
|
const description = toRecord(rawDescription);
|
||||||
|
if ('content' in description && description.content != null) {
|
||||||
|
return String(description.content);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(rawDescription);
|
||||||
|
}
|
||||||
|
|
||||||
/** Recursively render all nested object properties */
|
/** Recursively render all nested object properties */
|
||||||
function convertTemplateSyntax<T>(obj: T): T {
|
function convertTemplateSyntax<T>(obj: T): T {
|
||||||
if (typeof obj === 'string') {
|
if (typeof obj === 'string') {
|
||||||
|
|||||||
@@ -22,4 +22,39 @@ describe('importer-postman', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test('Imports object descriptions without [object Object]', () => {
|
||||||
|
const result = convertPostman(
|
||||||
|
JSON.stringify({
|
||||||
|
info: {
|
||||||
|
name: 'Description Test',
|
||||||
|
schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json',
|
||||||
|
},
|
||||||
|
item: [
|
||||||
|
{
|
||||||
|
name: 'Request 1',
|
||||||
|
request: {
|
||||||
|
method: 'GET',
|
||||||
|
description: {
|
||||||
|
content: 'Lijst van klanten',
|
||||||
|
type: 'text/plain',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result?.resources.workspaces).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
name: 'Description Test',
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
expect(result?.resources.httpRequests).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
name: 'Request 1',
|
||||||
|
description: 'Lijst van klanten',
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user