-
-
Notifications
You must be signed in to change notification settings - Fork 200
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
Valid JSON Schema not working for null-able response #388
Comments
Let me work on this |
If you need a quick fix
does the trick. |
Yeah, we are currently doing something like:
Although there is a workaround, this still feels out of place because it's only necessary at this top level (at least as I currently understand the issue). |
@Eomm why is it a good first issue? I'd not have a clue on how to fix this in Fastify. |
As I understand it, the problem lies in Line 102 in 8cde564
null but with the array. Accordingly, { type: [ "string", "number" ] } does not work either.So the question is whether we want to support arrays to specify different types? |
I think it would be a great idea! |
@matthyk FWIW, this "type as an array" comes from the JSON Schema way of specifying these. Not sure what impacts that would have on fast-json-stringify, as I'm not very familiar with it. |
Prerequisites
Fastify version
3.22.1
Plugin version
No response
Node.js version
14.x
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
20.04
Description
When trying to define a GET request that can return either an object or a null, the valid JSON Schema of
type: [ 'object', 'null' ]
is not supported by Fastify.FastifyError [FST_ERR_SCH_SERIALIZATION_BUILD]: Failed building the serialization schema for GET: /test, due to error object,null unsupported
I understand you are supposed to pass
nullable
but we do a lot of automatic schema generation, and needing to do this only in the case where the top-level response is in this situation is frustrating. It seems like this is at the intersection of Fastify, Open API 3 and JSON Schema, so I don't envy trying to navigate this, but as it stands this is a pretty confusing error to get.Steps to Reproduce
Create an endpoint whose response can be either a valid value or null.
Expected Behavior
Passing valid JSON Schema for a response that's a possible null object should work as it does at other levels schema definition.
The text was updated successfully, but these errors were encountered: