Skip to content

Instantly share code, notes, and snippets.

@sdesalas
Last active March 15, 2024 10:08
Show Gist options
  • Save sdesalas/5c9db8f60e1ff5081a6ea7fd693676a8 to your computer and use it in GitHub Desktop.
Save sdesalas/5c9db8f60e1ff5081a6ea7fd693676a8 to your computer and use it in GitHub Desktop.
Bug report use type `nullable` and `anyOf` in express-openapi-validator
**Describe the bug**
A clear and concise description of what happens.
Hiya. Thanks for putting together this awesome library.
We're trying to validate a response schema as follows:
```
properties:
name:
type: string
value:
# type: string # <--- validator needs this here to use `nullable`, however it still ignores it
nullable: true
anyOf:
- type: string
- type: boolean
- type: integer
- type: object
- type: array
```
**To Reproduce**
Steps to reproduce the behavior.
Use the openAPI schema above, validator with `validateResponses: true` and return a response as follows:
```
{
"name": "some key",
"value": null
}
```
**Actual behavior**
```
Error: /response/value must be string, /response/value must be boolean, /response/value must be integer, /response/value must be object, /response/value must be array, /response/value must match a schema in anyOf
```
A clear and concise description of what happens.
**Expected behavior**
A clear and concise description of what you expected to happen.
**Examples and context**
An example or relevant context e.g. an OpenAPI snippet, an Express handler function snippet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment