Skip to content

Commit dcc98fc

Browse files
nt0tskyn.totskii
andauthored
added update about discriminator support (#4)
Co-authored-by: n.totskii <n.totskiy@fxpro.com>
1 parent f88a87c commit dcc98fc

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

docs/faq.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,20 @@ A path like `/files/some/long/path` will pass validation. The Express `req.param
3131

3232
### **Q:** Can I use discriminators with `oneOf` and `anyOf`?
3333

34-
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)
35-
34+
- 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).
35+
- To also enable **deep discriminator** support (nested within `oneOf` / `anyOf`), set the `discriminator` option under `validateRequests`:
36+
37+
```js
38+
app.use(
39+
OpenApiValidator.middleware({
40+
apiSpec,
41+
validateRequests: {
42+
discriminator: true,
43+
//... other options
44+
}
45+
})
46+
);
47+
```
3648
---
3749

3850
### **Q:** What happened to the `securityHandlers` property?

docs/usage-validate-requests.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Determines whether the validator should validate requests.
1111
coerceTypes: false | true | 'array',
1212
removeAdditional: false | true | 'all' | 'failing',
1313
allErrors: false | true,
14+
discriminator: false | true,
1415
}
1516
```
1617

@@ -100,3 +101,34 @@ Determines whether the validator should validate requests.
100101
101102
- `true` - all rules should be checked and all failures reported
102103
- `false` - (**default**) stop checking rules after the first failure
104+
105+
- ### `discriminator`
106+
107+
> This option was introduced in version 5.6.0 to extend support for OpenAPI discriminators.
108+
109+
Enables validation of schemas that use OpenAPI `discriminator` fields with `oneOf` / `anyOf`.
110+
111+
By default, only **top-level discriminators** are supported.
112+
When this option is enabled, the validator also supports **deep (nested) discriminators** inside `oneOf` / `anyOf` structures.
113+
114+
**Option Schema**
115+
```javascript
116+
discriminator: false | true
117+
```
118+
119+
- `true` – enable validation of both top-level and deep discriminators
120+
- `false` – (**default**) only top-level discriminators are validated
121+
122+
**Example**
123+
```javascript
124+
app.use(
125+
OpenApiValidator.middleware({
126+
apiSpec,
127+
validateRequests: {
128+
discriminator: true,
129+
}
130+
})
131+
);
132+
```
133+
134+

0 commit comments

Comments
 (0)