Closed rido-min closed 1 year ago
When validating a Enum instance, if the value is not defined in the Enum, the validation message says:
.. does not match any name in schema
I think it should be
.. does not match any value in the Enum
repro:
[TestMethod] public void ValidateEnumStringInstance () { const string dtdl = @" { ""@context"": ""dtmi:dtdl:context;2"", ""@id"": ""dtmi:tests:enumString;1"", ""@type"": ""Interface"", ""displayName"": ""enumString"", ""contents"": [ { ""@type"": ""Property"", ""name"": ""aPropWithEnum"", ""schema"": { ""@type"": ""Object"", ""fields"": [ { ""name"": ""anEnumString"", ""schema"" : { ""@type"": ""Enum"", ""valueSchema"": ""string"", ""enumValues"": [ { ""name"": ""optionOne"", ""enumValue"": ""one"" }, { ""name"": ""optionTwo"", ""enumValue"": ""two"" } ] } } ] } } ] } "; var model = new ModelParser().Parse(dtdl)[new Dtmi("dtmi:tests:enumString;1")] as DTInterfaceInfo; var anEnumStringSchema = model.Properties["aPropWithEnum"].Schema; string instanceOk = @" { ""anEnumString"" : ""two"" }"; var validations = anEnumStringSchema.ValidateInstance(instanceOk); foreach (var validation in validations) Assert.AreEqual("", validation); Assert.AreEqual(0, validations.Count); string instanceFails = @" { ""anEnumString"" : ""four"" }"; validations = anEnumStringSchema.ValidateInstance(instanceFails); foreach (var validation in validations) Assert.AreEqual("\"anEnumString\" does not match any name in schema", validation); Assert.AreEqual(1, validations.Count); }
@rido-min, this can be closed now, can it not? This bug was fixed by #99 and tested by #101, both of which have been merged into main.
yes, if we link the PRs to the issues, those will be closed with the PR.
When validating a Enum instance, if the value is not defined in the Enum, the validation message says:
.. does not match any name in schema
I think it should be
.. does not match any value in the Enum
repro: