Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
32 changes: 32 additions & 0 deletions docs/usage-validate-requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
```

Expand Down Expand Up @@ -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,
}
})
);
```