Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,15 @@ function buildArray (context, location, input) {

if (Array.isArray(itemsSchema)) {
for (let i = 0, itemsSchemaLength = itemsSchema.length; i < itemsSchemaLength; i++) {
const item = itemsSchema[i]
let item = itemsSchema[i]
let itemLocation = itemsLocation.getPropertyLocation(i)
if (itemLocation.schema.$ref) {
itemLocation = resolveRef(context, itemLocation)
item = itemLocation.schema
}
const value = `value_${i}`
functionCode += `const ${value} = obj[${i}]`
const tmpRes = buildValue(context, itemsLocation.getPropertyLocation(i), value)
const tmpRes = buildValue(context, itemLocation, value)
functionCode += `
if (${i} < arrayLength) {
if (${buildArrayTypeCondition(item.type, value)}) {
Expand Down Expand Up @@ -747,10 +752,15 @@ function buildArray (context, location, input) {
const localUid = context.uid++
inlinedCode += `let addComma_${localUid} = false\n`
for (let i = 0, itemsSchemaLength = itemsSchema.length; i < itemsSchemaLength; i++) {
const item = itemsSchema[i]
let item = itemsSchema[i]
let itemLocation = itemsLocation.getPropertyLocation(i)
if (itemLocation.schema.$ref) {
itemLocation = resolveRef(context, itemLocation)
item = itemLocation.schema
}
const value = `value_${i}_${context.uid++}`
inlinedCode += `const ${value} = ${objVar}[${i}]`
const tmpRes = buildValue(context, itemsLocation.getPropertyLocation(i), value)
const tmpRes = buildValue(context, itemLocation, value)
inlinedCode += `
if (${i} < arrayLength_${objVar}) {
if (${buildArrayTypeCondition(item.type, value)}) {
Expand Down
28 changes: 28 additions & 0 deletions test/array.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,34 @@ buildTest({
dates: [new Date(1), new Date(2)]
})

buildTest({
title: 'dates tuple $ref',
definitions: {
dateTime: {
type: 'string',
format: 'date-time'
}
},
type: 'object',
properties: {
dates: {
type: 'array',
minItems: 2,
maxItems: 2,
items: [
{
$ref: '#/definitions/dateTime'
},
{
$ref: '#/definitions/dateTime'
}
]
}
}
}, {
dates: [new Date(1), new Date(2)]
})

buildTest({
title: 'string array',
type: 'object',
Expand Down