open-api
open-api copied to clipboard
Add support for `prefixItems`
From what I understand, OAS 3.1 should support the same validations offered by JSON Schema. It should be possible to define a type { type: 'array', minItems: 2, maxItems: 2, prefixItems: [...] } that would be used to define tuples.
https://json-schema.org/draft/2020-12/json-schema-validation.html
I hope I'm not mistaken, but currently it is not supported in this repository: https://github.com/kogosoftwarellc/open-api/blob/c805d4333c79891c29f8567dfc7f08da6334a64b/packages/openapi-types/index.ts#L148-L151
Although I cant find it in this codebase when using the package I can find this now
interface ArraySchemaObject extends BaseSchemaObject {
type: ArraySchemaObjectType;
items: ReferenceObject | SchemaObject;
prefixItems: ReferenceObject | SchemaObject;
}
which seems wrong to me? Shouldn't prefixItems be an array? Also not sure how it ends up in my nodeModules like this. I cant find prefixItems mentioned anywhere.
Yes prefixItems should be an array. See TupleSchemaObject in #865
Yeah I think, I accidentally added the file in node_modules 😏 . After I reinstalled the package it looks like openapi-types doesnt support prefixItems yet.
just a note, when using prefixItems, items: false is also valid.
see https://json-schema.org/understanding-json-schema/reference/array#additionalitems
Before to Draft 2020-12, you would use the additionalItems keyword to constrain additional items on a tuple. It works the same as items, only the name has changed.