diff --git a/docs/faq.md b/docs/faq.md index 1e6d480..93723cc 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -31,8 +31,20 @@ A path like `/files/some/long/path` will pass validation. The Express `req.param ### **Q:** Can I use discriminators with `oneOf` and `anyOf`? -Currently, there is support for top level discriminators. See [top-level discriminator example](https://github.com/cdimascio/express-openapi-validator/tree/master/examples/8-top-level-discriminator) - +- By default, only **top-level discriminators** are supported. See the [top-level discriminator example](https://github.com/cdimascio/express-openapi-validator/tree/master/examples/8-top-level-discriminator). +- To also enable **deep discriminator** support (nested within `oneOf` / `anyOf`), set the `discriminator` option under `validateRequests`: + +```js +app.use( + OpenApiValidator.middleware({ + apiSpec, + validateRequests: { + discriminator: true, + //... other options + } + }) +); +``` --- ### **Q:** What happened to the `securityHandlers` property? diff --git a/docs/usage-validate-requests.md b/docs/usage-validate-requests.md index 9718432..5ccbe54 100644 --- a/docs/usage-validate-requests.md +++ b/docs/usage-validate-requests.md @@ -11,6 +11,7 @@ Determines whether the validator should validate requests. coerceTypes: false | true | 'array', removeAdditional: false | true | 'all' | 'failing', allErrors: false | true, + discriminator: false | true, } ``` @@ -100,3 +101,34 @@ Determines whether the validator should validate requests. - `true` - all rules should be checked and all failures reported - `false` - (**default**) stop checking rules after the first failure + + - ### `discriminator` + + > This option was introduced in version 5.6.0 to extend support for OpenAPI discriminators. + + Enables validation of schemas that use OpenAPI `discriminator` fields with `oneOf` / `anyOf`. + + By default, only **top-level discriminators** are supported. + When this option is enabled, the validator also supports **deep (nested) discriminators** inside `oneOf` / `anyOf` structures. + + **Option Schema** + ```javascript + discriminator: false | true + ``` + + - `true` – enable validation of both top-level and deep discriminators + - `false` – (**default**) only top-level discriminators are validated + + **Example** + ```javascript + app.use( + OpenApiValidator.middleware({ + apiSpec, + validateRequests: { + discriminator: true, + } + }) + ); + ``` + +