Skip to content

AdditionalPropertiesKeyword error incorrectly thrown #148

Open
@brentscheffler

Description

@brentscheffler

If additionalProperties is set to false and a property value falls outside of the enum, an additional schema error of Additional object properties are not allowed is also returned.

Expected behavior

Only the The data should match one item from enum error should be returned.

Schema

{
	"type":"object",
	"properties": {
		"name": {
			"type": "string",
			"enum": ["apples", "oranges", "bananas"]
		},
		"published_at": {
			"type": "string",
			"format": "date-time"
		}
	},
	"required": ["name", "published_at"],
	"additionalProperties":false
}

Data

{
	"name": "kiwis",
	"published_at": "2025-01-20T05:06:49+00:00"
}

Error

#message: "The properties must match schema: {properties}"
      #subErrors: array:1 [
        0 => Opis\JsonSchema\Errors\ValidationError^ {#195
          #keyword: "enum"
          #schema: Opis\JsonSchema\Schemas\ObjectSchema^ {#215}
          #data: Opis\JsonSchema\Info\DataInfo^ {#216
            #value: "kiwis"
            #type: "string"
            #root: {#188}
            #path: array:1 [
              0 => "name"
            ]
            #parent: null
            #fullPath: null
          }
          #args: []
          #message: "The data should match one item from enum"
          #subErrors: []
        }
      ]
    }
    1 => Opis\JsonSchema\Errors\ValidationError^ {#219
      #keyword: "additionalProperties"
      #schema: Opis\JsonSchema\Schemas\ObjectSchema^ {#212}
      #data: Opis\JsonSchema\Info\DataInfo^ {#220
        #value: {#188}
        #type: "object"
        #root: {#188}
        #path: []
        #parent: null
        #fullPath: null
      }
      #args: array:1 [
        "properties" => array:2 [
          0 => "name"
          1 => "published_at"
        ]
      ]
      #message: "Additional object properties are not allowed: {properties}"
      #subErrors: []
    }

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