Open philsturgeon opened 5 years ago
This sounds like a valid addition.
Can you see a case where someone would want to throw InvalidInputError
but not InvalidTypeError
or vice versa? I was just thinking if one flag is enough.
Also, there might be a use case for doing something else in case of an error rather than just ignoring it. This would cause a mess if we add just one boolean flag now.
For now, the simplest solution would probably be to add one flag strictMode
and setting it to true
by default. If there comes a need to do something other than throwing in case of invalid type etc., we could just introduce a breaking change and bump up the version.
What do you think? :)
Yeah what you said! Agree that strictMode: true
is a good non breaking default and if people wanna get all particular they can suggest more options in the future.
I'm on a 12 hour train so I'll knock it out today.
@mikunn where are you man? I did the PR ages ago. #34
Can we add an flag to disable throwing on invalid types, or any other cases
InvalidInputError
? I'm volunteering to do it, just checking its something you'd want. I'm also not sure what to call it. "loose mode", "compat mode", etc.Background
Throwing on invalid types was introduced in v2.0.0, and it was a great feature to add to help people avoid writing invalid OpenAPI.
Working at Stoplight we deal with all sorts of specs, and sometimes folks have invalid OpenAPI which contains all sorts of JSON Schema-only stuff.
We try to guide people towards creating correct OpenAPI and JSON Schema with tools like Spectral providing general validation and specific guidance (no oneOf in OpenAPI v2, etc.) but having hard and early errors like this make it tough to use the tooling.
We need to convert OpenAPI to JSON Schema in various parts, so having it do the best conversion it can but just keep on trucking if it spots a problem would be really useful for us.
LMK what you think it should be called and I'll get it done. :)