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

Support for `discriminator` on deeper levels

Open code-surfer opened this issue 4 years ago • 5 comments

At the moment, discriminator is supported at the top level only. This seems to mean that e.g. an endpoint can return a body of schema A or B. Example 8 nicely demonstrates this. What does not seem to be supported is that an endpoint can return a body containing an array where its items can be of either schema C, D or E. Is such support planned? Is the currently limited support due to ajv? I don't see this limitation mentioned on https://ajv.js.org/json-schema.html#discriminator

Thank you!

code-surfer avatar Apr 22 '21 05:04 code-surfer

I would like to second this support.

Currently I have similar requirement in validating requests that accept an array containing several forms of objects.

My workaround is to define an object which have several properties but only allow one property when it's in use.

Look forward to discriminator support at deeper levels, and thanks again to the authors for this awesome tool!

raniantheone avatar May 20 '21 03:05 raniantheone

Hi there, is there any news on supporting discriminators in deeper levels?

AlmaKnudson avatar Jan 11 '22 01:01 AlmaKnudson

We could also need support for this.

Scenario: We have a object with an array where each item must be oneOf schema A, B or C. A, B and C have much in common, but should be mapped based on their status property.

# Example
type: object
properties:
  events:
    type: array
    items:
      oneOf:
        - $ref: '#/components/schemas/A'
        - $ref: '#/components/schemas/B'
        - $ref: '#/components/schemas/C'
      discriminator:
        propertyName: status
        mapping:
          A: '#/components/schemas/A'
          B: '#/components/schemas/B'
          C: '#/components/schemas/C'

karleinarb avatar Feb 08 '22 15:02 karleinarb