English 中文(简体)
含有属性B和C或D的json schema
原标题:json schema which either contains properties B and C or D
I defined the following schema: { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://example.com/schemas/test", "type": "object", "properties": { "A": { "type": "string" } }, "oneOf": [ { "properties": { "B": { "type": "integer" }, "C": { "type": "boolean" } } }, { "properties": { "D": { "type": "string" } } } ] } The idea is that the schema contains A, and either B,C or D. None of the elements are required. The following instance fails to validate: { "A": "world" }
问题回答
I believe you want anyOf instead of oneOf, because oneOf checks for exactly one of the subschemas, but in your test instance you don t have one of the subschemas. The docs are here: https://json-schema.org/understanding-json-schema/reference/combining#oneOf and you can test your schema here: https://json-schema.hyperjump.io/ which is where I find anyOf works in your case.




相关问题
XmlDocument.Validate ignore properties without [XmlIgnore]

I have a object that has a number of properties that aren t present in the xsd file. When doing XmlDocument.Validate is there a way I can tell it to ignore properties that are not present in the xsd ...

FOSS version of SQLCompare or something similar?

Actually, free is good enough, it doesn t have to be open source :) I m currently using the Schema Compare utility of VS2008, but it doesn t have a command line interface and has some other ...

How does Doctrine handle changes to the database schema?

In brief, what happens when you add a column to a table? What happens when you remove one? In more details, suppose you have the following: class User extends Doctrine_Record { public function ...

摘自XML Schema

我想要把复杂的XML化学仪编成册,并出口到C#文档中。

Using a schema other than dbo in LinqToSql Designer

Is there a way to specify in a data connection or the LinqToSql Designer a schema? Whenever I go to setup a data connection for LinqToSql there doesn t seem to be anyway to specify a schema and I ...

热门标签