- edited description
nullable in combination with anyOf is not correctly validated.
The OpenAPI 3.0 specification allows the definition of “nullable” anyOf Schemas like the following:
Foo:
type: object
properties:
nullableProperty:
nullable: true
anyOf:
- type: string
However swagger-request-validator does not seem to honor the nullable flag in this situation. The following JSON will incorrectly be marked as invalid:
{"nullableProperty" : null}
I have attached a complete unit test to reproduce this issue.
Comments (3)
-
reporter -
Any updates on this one? This seems like a major issue and it is stale for almost a year now.
-
This prevents very common use cases from being implemented, for instance given two business objects Widget and Spline where widgets have 0 or 1 splines we typically design response objects like this, mirroring the database rows:
{"widgets": [ {"id": 123, "name": "a widget with a spline", "spline_id": 789}, {"id": 456, "name": "a widget without a spline", "spline_id": null} ]}
Now normally you would write the Widget component schema such that it has a
spline_id
property which is a ref toSplineID
which is not nullable... you don't want the Spline component schema'sid
property to be nullable, after all, you want the Widget’s ownspline_id
to be sometimes null and sometimes a validSplineID
. With the limitation described by the OP, I don’t know how to document and validate this.Or when creating Widgets, you want the user to be able to specify that the widget they’re creating has a Spline (by passing a valid ID), or no Spline (by passing null). (Making the field itself optional is a possibility but it adds complexity to the client.)
- Log in to comment