The optional discriminator is an anyOf rather than a type, which causes this extra misleading error. You could argue it's a valid error, since types string and string | null can be different (in some languages). But I don't think rule INVALID_DISCRIMINATOR_TYPE fails if the discriminator is an optional literal string. So it's probably a bug related to optional $ref.
As of 11/10/23, typespec was generating the following autorest:
This caused two failures from OAV:
DISCRIMINATOR_NOT_REQUIRED
andINVALID_DISCRIMINATOR_TYPE
. Example in spec PR: https://github.com/Azure/azure-rest-api-specs/pull/26658/checks?check_run_id=18572542508The second failure is arguably a false positive, caused by the way
oav
processes optional ref types:The optional discriminator is an
anyOf
rather than atype
, which causes this extra misleading error. You could argue it's a valid error, since typesstring
andstring | null
can be different (in some languages). But I don't think ruleINVALID_DISCRIMINATOR_TYPE
fails if the discriminator is an optional literal string. So it's probably a bug related to optional$ref
.https://github.com/Azure/oav/blob/760a3352a04ebfcd2e9a1d05c7ad4925f20caa2c/lib/swaggerValidator/semanticValidator.ts#L358
In summary:
DISCRIMINATOR_NOT_REQUIRED
will fail.$ref
, ruleINVALID_DISCRIMINATOR_TYPE
will also fail.Related: https://github.com/Azure/typespec-azure/issues/3833