apiaryio / fury-adapter-swagger

Swagger 2.0 parser adapter for Fury.js
MIT License
11 stars 12 forks source link

Validate and discard invalid parameter values #124

Closed kylef closed 7 years ago

kylef commented 7 years ago

Parameter example values, default values and enumeration values are now validated against the parameter type and items. Any invalid parameter value will cause a warning and be discarded.

The following is now validated:

The following information is used for validations:

The first commit in this PR refactors converting a parameter to consistently use this.path like the rest of the code base instead of a passed path. This makes it easier to implement the feature in the following commit. The final commit in the PR removes a redundant piece of code.

honzajavorek commented 7 years ago

I'd be cautious about dropping the parameters, but if they're invalid, then it's probably correct behavior. Sometimes I'd be maybe more benevolent - I guess when people specify string and put number as example, there's definitely mismatch, but I'd go with warning + coercing the value instead of dropping the parameter altogether. Otherwise I think this should not affect Dredd much.

kylef commented 7 years ago

@honzajavorek I think what you propose can be done, but I do not think it would be simple. We wouldn't be able to coerce in a lot of combinations, the only things I think we can safely convert is number/boolean to string. I've made #126 with a start, do you have some other suggestions on types that can be safely coerced?

honzajavorek commented 7 years ago

I can't think of any other, actually. Coercing strings which look like numbers would be like PHP, I'm not sure we want to go that way. I believe having string as type and number as an example can be a common mistake, so this would be about smoother user experience.