fastify / fastify/fluent-json-schema

Object type ignored when nested properties use oneOf and raw

Open
#233 11 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
526
Forks
58
PR merge metrics
No merged PRs in 30d

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

4.23.2

### Plugin version

4.2.1

### Node.js version

20.x

### Operating system

macOS

### Operating system version (i.e. 20.04, 11.3, 10)

13.4

### Description

When I'm creating a schema like this:

```javascript
const schema = S.object().prop(
"content",
S.object()
.raw({ type: "object", discriminator: { propertyName: "type" } })
.oneOf([schema1, schema2]),
);
```

The `type: object` is omitted in the resulting JSON Schema both event if I use S.object() and raw type object. This can throw errors for example when using Ajv in strict mode. I do not know if the problem it's caused by the oneOf or the raw clause.

### Steps to Reproduce

You can see a full reproduction example here: https://codesandbox.io/p/sandbox/infallible-cloud-4kw5xm. Run npm start.

### Expected Behavior

The resulting JSON schema should not be this:
```
{
'$schema': 'http://json-schema.org/draft-07/schema#',
type: 'object',
properties: { content: { discriminator: [Object], oneOf: [Array] } }
}
```

but this:

```
{
'$schema': 'http://json-schema.org/draft-07/schema#',
type: 'object',
properties: { content: { type: 'object', discriminator: [Object], oneOf: [Array] } }
}
```

It seems that this issue is not present on schemas root level oneOf/raw.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.