Skip to content

Object type ignored when nested properties use oneOf and raw #233

Description

Prerequisites

  • I have written a descriptive issue title
  • 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:

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions