Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
erayd opened this issue Mar 8, 2017 · 2 comments
Open

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

erayd opened this issue Mar 8, 2017 · 2 comments

Comments

@erayd
Copy link
Contributor

erayd commented Mar 8, 2017

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?

@erayd
Copy link
Contributor Author

erayd commented Mar 13, 2017

No response to this, so have started working on a PR to add a 'strict' mode that will detect and validate against the exact version of the spec being used, with a fallback to the current 'permissive' model if the version can't be accurately determined. That should render this issue moot.

@DannyvdSluijs
Copy link
Collaborator

@erayd maybe a long shot but i would rather ask now then get a comment later. Do you by chance have a branch somewhere with you work on this topic?

This issue might play a key role in supporting other drafts.

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

No branches or pull requests

2 participants