Description
Hi team,
In the upcoming v3.1.0 spec we will be allowed to use type: "null" definitions.
Using a discriminator allows us to quickly move through an inheritance tree using the discriminator.propertyName passed in a payload.
So if discriminator.propertyName = "animalType"
and we deserialize an Animal with the payload {"animalType: "Dog"} this works.
But sometimes users want to pass in empty payload values like null or empty dict {}.
Should we allow those types in the oneOf definition when we are in a composed schema?
Question 1: clarification on using type: "null" + object in oneOf w/ discriminator
Should this be valid?
Animal:
oneOf:
- $ref: NullType
- $ref: Pet
- $ref: ObjectType
discriminator:
propertyName: animalType
NullType:
type: "null"
ObjectType:
type: object
Some context in python is that None and {} are both Falsey values for a variable that holds a dict.
My proposal is that we allow these null and {} empty types because some clients will expect, accept and understand these empty/zero-state values.
This would allow for rapid deserialization through an inheritance tree while also allowing servers to return null/{} empty state values.
Note about the where we would include type: object
in the oneOf list:
If we do allow empty object type, then we may want to list it last.
That would be safer for generator that loop through oneOf types and deserialize if the payload matches the schema. That would allow a match on Pet before {}.
This point applies more when one includes type: object
without using a discriminator in Animal.
Because order matters for that use case, it would be simplest if we require that the type: object
definition be the last one when used in oneOf.
@handrews @philsturgeon @tedepstein @johncmunson
This question came up here
Question 2: clarification on using type: type: "null" + object in anyOf without discriminator
Should this be invalid?
Animal:
allOf:
- $ref: Blah
anyOf:
- type: null
- type: object
I think that null and type: object should be invalid in anyOf definition.
Question 3: clarification on using type: type: "null" + object in allOf without discriminator
What should we do for allOf?
Animal:
allOf:
- type: null
- type: object
Type null should be invalid because it does not apply to object schemas
Type: object. Not sure about how I feel on this one, it adds no new information to the schema.