Skip to content

Commit 9707b7e

Browse files
committed
Add support for prefixItems from draft-2020-12
1 parent 43ba08b commit 9707b7e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/normalizer.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,27 @@ rules.set('Remove maxItems if it is big enough to likely cause OOMs', (schema, _
161161
}
162162
})
163163

164+
// NOTE: https://json-schema.org/draft/2020-12#introduction
165+
//
166+
// Keywords for Applying Subschemas to Arrays
167+
// https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.9.3.1
168+
// https://json-schema.org/draft/2020-12/json-schema-core#section-10.3.1
169+
rules.set('Support the `prefixItems` key from draft 2020-12', schema => {
170+
if (!isArrayType(schema)) {
171+
return
172+
}
173+
174+
if (schema.hasOwnProperty('prefixItems')) {
175+
if (schema.hasOwnProperty('items')) {
176+
schema.additionalItems = schema.items as any
177+
delete schema.items
178+
}
179+
180+
schema.items = schema.prefixItems as any
181+
delete schema.prefixItems
182+
}
183+
})
184+
164185
rules.set('Normalize schema.items', (schema, _fileName, options) => {
165186
if (options.ignoreMinAndMaxItems) {
166187
return

0 commit comments

Comments
 (0)