-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Incompatibility between JSON Schema validation & OpenAPI specification #19
Comments
Ya, very interesting discovery. That's a bit of a inconsistency for sure. Let me dig into this for a bit and see what I come up with. Thanks. |
@JoeAlamo So, there's been extensive discussion on this topic by OpenAPI spec contributors. There's even a proposal to clarify the usage of Feel free to read it all, but the part that pertains to this issue is:
More simply, using "type" : ["string", "null"] |
Yep, bit of an ongoing saga! But therein lines the conundrum - if you modify your OpenAPI 3.0 spec file to have And any other tooling you are using for OpenAPI will break (SwaggerUI, linters, other doc generation tools etc.). Stuck between a rock and a hard place :/ This is being addressed in OpenAPI 3.1, but that will take some time to be finalised and tooling vendors to offer support (some more info in https://apisyouwonthate.com/blog/openapi-v31-and-json-schema-2019-09 and OAI/OpenAPI-Specification#1977). The only solutions I can think of to work with OpenAPI 3.0 as is are the ones I listed in the OP |
I suppose I could detect if you're using < OAS 3.1 and treat it specially. Would that work? |
I think that could work (perhaps targeting https://github.com/thephpleague/openapi-psr7-validator looks promising, but it seems Laravel and PSR-7 aren't the best of friends - and the types of error messages could be very different to what you get from |
Ya I think I'll stick with |
Here's a PR for adding support for It doesn't apply to 3.1.x specs, since Code of interest: https://github.com/hotmeteor/spectator/pull/20/files#diff-a98ad63f96e6bc68609a93c68c484bd021aee76560a9c5fc3a0f59c5b75359a0R163 |
@JoeAlamo Do you want to take that PR for a spin and see if it does what you expect? |
Hey there,
I have been testing this package and I think I have came across an issue which I believe is the result of an incompatibility between the JSON Schema validation being performed, and the OpenAPI specification.
If I have an OpenAPI response with some nullable attributes, I might have that defined like:
using
nullable: true
, in accordance with OpenAPI 3.0 spec.If in my tests, I have a response for that endpoint like the following:
I will receive a
Opis\JsonSchema\ValidationError
withkeyword = "favourite_colour"
andkeywordArgs = ["expected" => "string", "used" => "null"]
.This error is a valid error, from a JsonSchema point of view. To mark something as nullable in JsonSchema, you provide
type
as an array, such astype: [string, null]
.However, whilst that would satisfy JsonSchema, that is invalid according to OpenAPI 3.0 specification.
There may be more cases like that, but that is the only one I have came across.
This feels like quite a fundamental problem. The only solutions I can think of are:
I do hope there is something I've been doing wrong to get these errors but there more I've looked at it, the Json Schema / OpenAPI incompatibility has seemed like the cause!
The text was updated successfully, but these errors were encountered: