Skip to content

JSON schema does not explicitly add "additionProperties: false"  #41

@crobinson42

Description

@crobinson42

This validator:

v
  .object({
    id: v.string().required(),
    username: v.string(),
    nested: v.object({
      email: v.string(),
    }),
  })

Will produce this json-schema:

{
  type: 'object',
  properties: {
    id: { type: 'string' },
    username: { type: 'string' },
    nested: { type: 'object', properties: [Object] }
  },
  required: [ 'id' ]
}

The problem here is that JSON-schema validators like ajv infer if there is no additionalProperties: false then additional properties are allowed. This conflicts with the implementation of the ObjectValidator because if you want to allow additional properties you are required to chain .additional({ ... }) which should imply to the developer that when .additional({...}) is not used then to expect _additionalProperties: false_ in the json-schema output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions