2

JsonSchema に有効なスキーマが含まれているかどうかを検出しようとしています。私の知る限り、Json.NET には JSON スキーマを検証する方法がありません。

完全に無効なスキーマで JsonSchema を作成できるようで、次のように文句を言うことはありません。

var invalidSchema = JsonSchema.Parse(@"{ ""title"": { ""Invalid"": ""Invalid"" } }");

次に、無効なスキーマに対して JObjects を検証すると、true が返されます。記録のために、公開されたdraft-03自己記述スキーマによると、上記の「スキーマ」は有効ではありません( JSON Schema Lintで確認しました)。

私はdraft-03を解析して他のスキーマを検証しようとしましたが、うまくいきませんでした。解析しようとすると例外が発生します。

Newtonsoft.Json.JsonReaderException was unhandled by user code
  HResult=-2146233088
  Message=Exception JSON schema type string token, got StartObject. Path 'properties.type.items.type[1]', line 11, position 6.
  Source=Newtonsoft.Json
  LineNumber=11
  LinePosition=6
  Path=properties.type.items.type[1]
  StackTrace:
       at Newtonsoft.Json.Schema.JsonSchemaBuilder.ProcessType()
       at Newtonsoft.Json.Schema.JsonSchemaBuilder.ProcessSchemaProperty(String propertyName)
       at Newtonsoft.Json.Schema.JsonSchemaBuilder.BuildSchema()
       at Newtonsoft.Json.Schema.JsonSchemaBuilder.ProcessItems()
       at Newtonsoft.Json.Schema.JsonSchemaBuilder.ProcessSchemaProperty(String propertyName)
       at Newtonsoft.Json.Schema.JsonSchemaBuilder.BuildSchema()
       at Newtonsoft.Json.Schema.JsonSchemaBuilder.ProcessProperties()
       at Newtonsoft.Json.Schema.JsonSchemaBuilder.ProcessSchemaProperty(String propertyName)
       at Newtonsoft.Json.Schema.JsonSchemaBuilder.BuildSchema()
       at Newtonsoft.Json.Schema.JsonSchemaBuilder.Parse(JsonReader reader)
       at Newtonsoft.Json.Schema.JsonSchema.Read(JsonReader reader, JsonSchemaResolver resolver)
       at Newtonsoft.Json.Schema.JsonSchema.Parse(String json, JsonSchemaResolver resolver)
       at Newtonsoft.Json.Schema.JsonSchema.Parse(String json)
  InnerException: 
4

0 に答える 0