diff --git a/plugins/importer-openapi/src/index.ts b/plugins/importer-openapi/src/index.ts
index 1629bf8e..4bc4c824 100644
--- a/plugins/importer-openapi/src/index.ts
+++ b/plugins/importer-openapi/src/index.ts
@@ -1139,7 +1139,7 @@ function formatMediaTypeBody(
) {
return typeof example === "string"
? example
- : valueToXml(example, schema, importState, "root");
+ : valueToXml(example, schema, importState, "root", true);
}
return formatBodyText(example);
}
@@ -1149,18 +1149,18 @@ function valueToXml(
schema: unknown,
importState: ImportState,
elementName: string,
+ isDocumentRoot = false,
): string {
const resolvedSchema = toRecord(importState.resolve(schema));
const schemaXml = toRecord(resolvedSchema.xml);
if (Array.isArray(value)) {
const itemSchema = importState.resolve(resolvedSchema.items);
+ const shouldWrap = schemaXml.wrapped === true || isDocumentRoot;
const itemName =
stringAt(toRecord(itemSchema).xml, "name") ??
- (schemaXml.wrapped === true ? stringAt(schemaXml, "name") ?? elementName : elementName);
+ (shouldWrap ? stringAt(schemaXml, "name") ?? elementName : elementName);
const items = value.map((item) => valueToXml(item, itemSchema, importState, itemName)).join("");
- return schemaXml.wrapped === true
- ? xmlElement(elementName, schemaXml, items)
- : items;
+ return shouldWrap ? xmlElement(elementName, schemaXml, items) : items;
}
if (isRecord(value)) {
const properties = toRecord(resolvedSchema.properties);
diff --git a/plugins/importer-openapi/tests/index.test.ts b/plugins/importer-openapi/tests/index.test.ts
index 5b39f6e5..bae84448 100644
--- a/plugins/importer-openapi/tests/index.test.ts
+++ b/plugins/importer-openapi/tests/index.test.ts
@@ -1071,6 +1071,23 @@ describe("importer-openapi", () => {
responses: {},
},
},
+ "/values": {
+ post: {
+ requestBody: {
+ content: {
+ "application/xml": {
+ schema: {
+ type: "array",
+ example: ["one", "two"],
+ xml: { name: "values", wrapped: false },
+ items: { type: "string", xml: { name: "value" } },
+ },
+ },
+ },
+ },
+ responses: {},
+ },
+ },
},
}),
);
@@ -1083,6 +1100,9 @@ describe("importer-openapi", () => {
'A' +
"",
});
+ expect(imported?.resources.httpRequests[1]?.body).toEqual({
+ text: "onetwo",
+ });
});
test("Omits read-only properties from generated request bodies", async () => {