I have multiple drop-downs in the form I am implementing. I do not want to expose the underlying keys in the UI, so I am using oneOf in the schema so I can specify titles.
This is working fine, and I am getting the ‘const’ value in the data.
However, when I send this JSON back to my API, it is not passing schema validation. The string value is not detected as ‘oneOf’ the provided options (I guess because they are objects).
I am using NewtonSoft.Json in my .NET 7 C# API for validation.
In the interrim, I have written some code to convert oneOf properties in the schema to an ‘enum’ of the keys before validation, so the validation can pass. But I don’t like this solution.
I have a few questions:
- Is the data I am getting back from JsonForms valid to the schema I provide? Since the result is a string key, but the oneOf options are objects
- Is this an issue with Newtonsoft itself?
- If so, has anybody encountered this before? How did you overcome it?
Here is an example schema:
{
"type": "object",
"required": [
"USER"
],
"properties": {
"$schema": {
"type": "string"
},
"USER": {
"type": "string"
},
"PASSWORD": {
"type": "string"
},
"SINGLE_CHOICE": {
"type": "string",
"title": "Single choice",
"description": "Some description",
"oneOf": [
{
"const": "Yes",
"title": "Yes"
},
{
"const": "No",
"title": "No"
}
]
},
"MULTI_CHOICE": {
"type": "array",
"title": "Multi choice",
"description": "Some description",
"uniqueItems": true,
"items": {
"type": "string",
"oneOf": [
{
"const": "A",
"title": "A"
},
{
"const": "B",
"title": "B"
},
{
"const": "C",
"title": "C"
}
]
}
}
},
"additionalProperties": false
}
And is some example data I am validating against in a format it would come back from Json forms
{
"$schema": "./schema_camel.json",
"USER": "value",
"SINGLE_CHOICE": "Yes",
"MULTI_CHOICE": ["A", "C"]
}