-
Notifications
You must be signed in to change notification settings - Fork 352
Attribute validation and Overflow
This table lists how overflow is "encoded" in the POCO model, and which validator will catch the error.
Kind of error | How encoded | Detected by(1) |
---|---|---|
Incorrect primitive value | Incorrect value is stored in primitive's ObjectValue | ValidateObjectValue() |
Expected primitive, got object | (Dynamic)object is stored in primitive's ObjectValue | ValidateObjectValue() |
Expected object, got primitive | Store in overflow, with correct type "attached" (2) | SetValue(3)+ValidateObject |
Expected single, got array | Store in overflow, with correct type "attached" (2) | SetValue(3)+ValidateObject |
Expected array, got single | Store in overflow, with correct type "attached" (2) | SetValue(3)+ValidateObject |
Choice where no choice allowed | Added as unknown element to overflow | See Unknown element below |
Invalid choice type | Property (type of DataType) is set to the value | AllowedTypes attribute |
Unknown choice type | Property is set to a DynamicDataType value | AllowedTypes attribute |
Unknown resource type | Property is set to a DynamicResource value | AllowedTypes attribute (4) |
Unknown element | Store in overflow, with "no type" attached | SetValue(3)+ValidateObject |
(1) The property's getter (except for JsonValue) also detects it, and throws. We still might need an unsafe marker to do this efficiently. The setter needs to detect invalid values to remove any entries from the overflow dictionary when a new value is set.
(2) This probably means the overflow needs to contain tuples or types which allow for a value + expected type.
(3) We need detection in ValidateObject for .NET attribute validation, but in either SetValue or TryGetValue for the parser, since the parsers need to be able to validate each property as they parse them, calling ValidateObject is too late (no more position info available). This probably means we need to change the signature of SetValue or TryGetValue to also be able to get the error. Or we add an explicit ValidateProperty(name)
to the generated code. Or we let it be detected by ValidateObject
for attribute validation, and by the json/xml parser during parsing (two separate detections paths).
(4) Normally, nested resources are marked with [AllowedTypes(typeof(Hl7.Fhir.Model.Resource))]
, we should make sure that in that case we complain about finding a DynamicResource.