What is the proper method for utilizing the "oneOf" keyword in this schema?

Is it possible to have either option A or B, but not both (mutually exclusive)?

In Draft 3, I am required to use whatever is available, even though the version on top says 4. This is because when using an array for "required", it throws an error stating that it cannot convert an array to a boolean. If arrays are removed without specifying the use of draft 4, Newtonsoft.Json.Schema.Extensions::IsValid does not validate properly and returns "true" randomly.

Unfortunately, I must utilize an outdated version of Newtonsoft.

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "description": "",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "SearchCriteria": {
      "type": "array",
      "uniqueItems": true,
      "minItems": 1,
      "required": true,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "A": {
            "type": "string",
            "minLength": 1,
            "pattern": "^[^\\s]*$"
          },
          "B": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1,
              "pattern": "^[^\\s]*$",
              "enum": ["One", "Two"]
            },
            "minItems": 1
          },
          "C": {
            "type": "string",
            "required": true,
            "minLength": 2
          },
          "D": {
            "type": "array",
            "required": true,
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "uniqueItems": true
          }
        }
      }
    }
  }
}

Answer №1

Draft 3 does not have support for OneOf or similar features, as pointed out in a comment by @dbc.

[Newtonsoft.Json.Schema.JsonSchema]
utilizes draft 3 to interpret the JSON file. This is why it was disregarding OneOf and generating an error for "required" being presented as an array. In draft 3, "required" can only be a boolean.

To address this issue, utilize [Newtonsoft.Json.Schema.JSchema] to decode the Schema as a string, [Newtonsoft.Json.Linq.JToken] to decode the JSON as a string, and

[Newtonsoft.Json.Schema.SchemaExtensions]
to validate instead of using
[Newtonsoft.Json.Schema.Extensions]
.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Why won't my controller function fire with ng-click in AngularJS?

I'm having trouble getting a function to execute when my button is clicked. Despite the fact that this code appears correct, the function defined in my controller isn't being triggered. The code compiles without errors as shown in the console. A ...

Converting JSON to CSV with flexible array lengths: Harnessing the power of jq

I have retrieved a JSON data with the given structure { "type": "conversation", "id": "1234", "created_at": 1425586662, "initial_message": { "type": "initial_message", "id": "567", "body": "<p>Testing</p> ...

Create a soft focus on the background sans any filters

I am in the process of developing a website and have implemented code to blur out the background: CSS #background{ background: url(img/bg.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o ...

React throws a "ReferenceError: indexedDB is not defined" but surprisingly, it still manages to function properly

I utilized yarn to install idb-keyval By utilizing the following code, I imported it: import { set } from 'idb-keyval'; Then, I assigned a value to a variable using the following code snippet: set('hello', 'world'); Althou ...

javascript: window.open()

I am currently using VB.NET 2005 and I have a requirement to launch a new browser window using Process.Start(). The challenge is that I need to specify the size of the browser window, for example, height:300 and width:500. Process.Start("firefox.exe", "ab ...

Monitor the user's attendance by utilizing two separate for loops

I'm currently developing an angularjs attendance tracking system and I'm facing challenges when it comes to accurately counting the number of days an employee is absent. Despite attempting to solve this issue with two nested for loops, I am still ...

The issue of the selection option not being cleared after being set to 0 persists in JavaScript

I am facing an issue where I need to reset the select option to `0` when another option is selected. I have tried the code below for this purpose. if (varALPO1MobNum == "0") { var selectElement = $(&apo ...

Image gradually disappears after being loaded via ajax request

I am trying to achieve a fade-in effect for images after they have been loaded following an ajax call. The goal is to make the fade-in occur smoothly, rather than having the user observe the image loading process. Is there anyone who can assist me with ...

Several conditional statements in JSX

In my JSX Return() code, I am encountering an "If" issue when one of my conditions has 2 different 'onClick' events. There are 2 'a' tags, where one will display button 'X' if a statement is true and the other will display but ...

Building a hive table to query a detailed parquet file

My goal is to overlay a hive table on top of a parquet table I created from the provided json data: {"user_id":"4513","providers":[{"id":"4220","name":"dbmvl","behaviors":{"b1":"gxybq","b2":"ntfmx"}},{"id":"4173","name":"dvjke","behaviors":{"b1":"sizow", ...

Is it not possible to generate HTML tags using jQuery and JavaScript in JSF?

I'm currently working with jsf 2.0 and richfaces 4.0 to develop my application. Occasionally, I incorporate jQuery and JavaScript functions for displaying and hiding elements. However, I've encountered an issue when trying to generate tags within ...

Exploring nested JSON information through jQuery's AJAX call

I am encountering an issue with accessing JSON data using a jQuery AJAX request in JavaScript. I keep receiving a 'Cannot read property [0] of undefined' error in the console of Google Chrome. Despite trying different approaches, such as referrin ...

Implementing a loop in JSON with Angular: A step-by-step guide

I have a task to generate a JSON structure that looks like the following: "combinationsData":[ { "combinationName":"2_2", "dataGroups": [ { "tableType":"2",//This value comes from HTML "twoAxisDat ...

Adding a line and text as a label to a rectangle in D3: A step-by-step guide

My current bar graph displays values for A, B, and C that fluctuate slightly in the data but follow a consistent trend, all being out of 100. https://i.stack.imgur.com/V8AWQ.png I'm facing issues adding lines with text to the center of each graph. A ...

Combining Ajax Form with Django to handle and display errors in form submissions

I am attempting to save information from a form into my Database using Django and Python for the backend. Below is the HTML form: <form> <center> <div class="container-fluid"> <div class="row"> <div clas ...

Is there a way to retrieve data from both JSON and a file simultaneously?

I'm trying to use JavaScript fetch API to upload a photo message with text to Discord webhook. How can I upload both my JSON data and file? var discordWebHookBody = new FormData() discordWebHookBody.append("map", map) discordWebHookBody.appe ...

What are the benefits of using "var self = this" for synchronizing between a class and events?

Consider this straightforward code example (it's in AngularJS for simplicity, but the scenario is common in JavaScript): angular.module('app',[]). directive('myDir', function(){ this.state = {a:1, b:2}; return { l ...

Tips for creating a unified user interface framework for various web applications sharing a consistent design

Struggling to create a user interface framework for multiple web applications, I'm faced with the challenge of setting up the infrastructure in our unique situation: We have 7 (or more) different web applications built using asp.net mvc Some of thes ...

Obtaining asynchronous data with nodejs is possible through several methods

I am currently trying to retrieve data from a MySQL table using Node.js. I have a SQL routine in another Node.js file that I am calling, but I am struggling to get the callback function to return the data. I suspect that the issue may be related to calling ...

converting web job json data into a pandas dataframe

Currently, I am endeavoring to retrieve JSON data for logs from Azure WebJobs services using the REST API. While I have managed to extract the data into a dataframe with various columns, my goal is to format the "lastrun" column in a tabular layout, where ...