Skip to content

Type validation conflict between draft-03 and later versions #374

Open
@erayd

Description

@erayd

Currently, the validator does the following on unknown type values:

throw new InvalidArgumentException((is_object($value) ? 'object' : $value) . ' is an invalid type for ' . $type);

This code violates draft-03, but correctly enforces draft-04 and later versions of the spec, which do not allow arbitrary type values.

Draft-03 says the following:

If the property is not defined or is not in this list, then any type of value is acceptable. Other type values MAY be used for custom purposes, but minimal validators of the specification implementation can allow any instance value on unknown type values.

In addition, the list of valid type values includes any, which is valid under draft-03, but violates draft-04 and newer versions of the spec, which say that the type value MUST be one of the seven core primitive types.

Obviously validating the schema first would catch this... but if the user doesn't do that, then IMO we should do the following:

  • If we can determine the schema spec in use, follow the correct behavior for that spec.
  • If we can't determine the spec, then assume draft-03 (which is the more permissive standard), but emit a warning of some kind - may need to build a mechanism for this (I might do a PR for such a mechanism regardless, as it's useful in other areas).

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions