fastify / fastify/fastify-swagger
Null type in JSON schema ignore when generating swagger.
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 219
- Avg merge
- 4h 24m
- Merged PRs (30d)
- 2
Description
### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
3.29.0
### Plugin version
6.0.1
### Node.js version
16.13.1
### Operating system
macOS
### Operating system version (i.e. 20.04, 11.3, 10)
12.3.1
### Description
I'm using [Typebox](https://www.npmjs.com/package/@sinclair/typebox) to generate JSON schemas for an endpoint's response. In one endpoint some response properties may be `null`.
In Typebox we defined it as follow
```javascript
Type.Union([Type.String(), Type.Null()]
```
Which seems to generate the correct JSON schema
```json
{
"anyOf": [
{ "type": "string" },
{ "type": "null" }
]
}
```
The generated swagger file does not indicate that field can be nullable (which cases some of our tests to fail).
### Steps to Reproduce
Create a schema with a property with type
```json
{
"anyOf": [
{ "type": "string" },
{ "type": "null" }
]
}
```
Generate swagger file.
### Expected Behavior
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.