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

Automatically casts numeric strings to integer even if spec says it's a string #62

Closed
Aaronmacaron opened this issue Aug 22, 2019 · 6 comments

Comments

@Aaronmacaron
Copy link

Aaronmacaron commented Aug 22, 2019

This issue is closely related to #58 .

I have a path parameter that is a string. Though, if I pass a string that is numeric such as "123" you automatically cast it to an integer:

https://github.com/lezhnev74/openapi-psr7-validator/blob/master/src/PSR7/OperationAddress.php#L98

This leads to the validation failing because the parameter is expected to be a string but it isn't because you cast it to an integer.

You should probably check if the specification says that the parameter is a string and if so don't cast it to an integer.

@lezhnev74
Copy link
Owner

Good catch!
Yeah, URLs serialize anything as a string, deserialization is not so straightforward. Probably optimistic casting to int is not the perfect solution.

@lezhnev74
Copy link
Owner

Well, I've prepared a small patch which removes the casting feature (which is "too smart").
I can't remember why it was introduced in the first place though.

@Aaronmacaron
Copy link
Author

Great! I think this resolves my problem. Thanks for the quick solution.

When do you think this will be merged/released?

@lezhnev74
Copy link
Owner

I am expecting some extra feedback from @scaytrase If nothing pops up today, I think I'll tag 0.16

lezhnev74 added a commit that referenced this issue Aug 23, 2019
#62 remove "smart" casting of parsed params to numerics
@lezhnev74
Copy link
Owner

Tagged. Did it help?

@Aaronmacaron
Copy link
Author

Yep. It solved my problem. Thank you 👍

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

2 participants