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

Casting nonsense string to number with $pragma.cast gives valid result. #108

Open
adjenks opened this issue Jun 21, 2022 · 0 comments
Open

Comments

@adjenks
Copy link

adjenks commented Jun 21, 2022

Based on your documentation it could just be doing exactly as described:

From To Result
string integer try to parse the integer from string, 0 if invalid number representation

However I don't see how it's useful to cast everything to 0 when casting fails.

I'd rather it something like "{type1} required, could not convert given {type2} value to {type1}."

What's the logic behind casting everything to 0 on failure?

I'm replacing the pragma cast to this for now:

{
		"field_name": {
			"title": "Field Name",
			"oneOf": [
				{
					"type": "integer"
				},
				{
					"type": "string",
					"pattern": "^\\d+$"
				}
			]
		},
}

If there is another way to do this, I'd be happy to know.

What I really want is for anything that's supposed to be a number but is a string, it should have an attempted cast, but if the cast fails, then fail to validate and provide a message as mentioned before.

Thank you for listening. Keep up the good work.

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

No branches or pull requests

1 participant