Skip to content

Commit 5fc09e7

Browse files
authored
fix: undefined error for xml when example is defined (#175)
1 parent 1dde94c commit 5fc09e7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export function applyXMLAttributes(result, schema = {}, context = {}) {
115115
}
116116

117117
if (schema.example !== undefined && !wrapped) {
118-
propertyName = schema.items.xml?.name || propertyName;
118+
propertyName = schema.items?.xml?.name || propertyName;
119119
}
120120
}
121121
if (schema.oneOf || schema.anyOf || schema.allOf || schema.$ref) {

test/integration.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,30 @@ describe('Integration', () => {
881881
const options = {
882882
format: 'xml',
883883
};
884+
885+
it('should build XML for an array with nested array', () => {
886+
const schema = {
887+
type: 'object',
888+
properties: {
889+
name: {
890+
type: 'array',
891+
items: {
892+
type: 'string',
893+
example: ['John', 'Smith'],
894+
}
895+
}
896+
}
897+
};
898+
const result = sample(schema, options, {});
899+
900+
expect(result.trim()).toMatchInlineSnapshot(`
901+
"<name>
902+
<0>John</0>
903+
<1>Smith</1>
904+
</name>"
905+
`);
906+
});
907+
884908
it('should build XML for an array with wrapped elements without examples', () => {
885909
const schema = {
886910
type: 'object',

0 commit comments

Comments
 (0)