express-openapi-validator icon indicating copy to clipboard operation
express-openapi-validator copied to clipboard

`allOf` and `oneOf` don't work as NonArraySchemaObject always requires type property to be defined

Open LinusMelb opened this issue 4 years ago • 1 comments
trafficstars

https://github.com/cdimascio/express-openapi-validator/blob/a585ba18ac3f613d2669c3c19dbc0097ca6d9659/src/framework/types.ts#L234-L251

As line 249 shows, type property is always required for NonArraySchemaObject however if I'd like to use oneOf keyword what value the type property should be? For example:

properties: {
    // this property can be either string or number
    stringOrNumber: {
        type: '', // this property is always required however in this case I explicitly defined  `oneOf` below
        oneOf: [{type: 'string'}, {type: 'number'}],
    }
}

LinusMelb avatar Apr 14 '21 00:04 LinusMelb

I ran into this as well; this was my workaround:

{
  type: undefined as unknown as "object",
  oneOf: [...],
}

rattrayalex avatar Sep 02 '21 05:09 rattrayalex