open-api icon indicating copy to clipboard operation
open-api copied to clipboard

Add support for `prefixItems`

Open edobrb opened this issue 2 years ago • 3 comments

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

edobrb avatar May 02 '23 08:05 edobrb

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.

saschahofmann avatar Aug 16 '23 15:08 saschahofmann

Yes prefixItems should be an array. See TupleSchemaObject in #865

edobrb avatar Aug 17 '23 08:08 edobrb

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.

saschahofmann avatar Aug 17 '23 12:08 saschahofmann

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.

benjamine avatar Oct 28 '24 14:10 benjamine