Skip to content

Root level required creates invalid schema #132

@erfanium

Description

@erfanium

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure it has not already been reported

Fastify version

3.0.0

Plugin version

3.0.0

Node.js version

16.2.0

Operating system

Linux

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

18.04

Description

I think root level required calls should be ignored, because it creates an invalid schema

Steps to Reproduce

const s = S.object().required().prop('foo', S.string())
ajv.compile(s.valueOf())

Result:

Error: schema is invalid: data/required/0 must be string

Because s.valueOf().required array contains a symbol but it expected to be an array of string

Expected Behavior

S.object().required().prop('foo', S.string()).valueOf() should return a valid json-schema

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