-Change BSON writer to write new binary subtype

-Fix BSON reader to read the old binary subtype correctly
-Added JsonNet35BinaryCompadibility to BSON reader for incorrectly written BSON binary values
-Changed JSON schema to use required flags instead of optional as defined in JSON schema spec 3.0
-Changed JSON schema to use divisibleBy instead of maxDecimals as defined in JSON schema spec 3.0
-Fixed detection of serialization specified flag properties
-Updated to latest version of NuGet
This commit is contained in:
JamesNK
2010-12-19 00:29:41 +00:00
parent 2e7b8e5279
commit 5ccd826951
20 changed files with 194 additions and 80 deletions
+3 -3
View File
@@ -49,9 +49,9 @@ namespace Newtonsoft.Json.Schema
/// </summary>
public string Title { get; set; }
/// <summary>
/// Gets or sets whether the object is optional.
/// Gets or sets whether the object is required.
/// </summary>
public bool? Optional { get; set; }
public bool? Required { get; set; }
/// <summary>
/// Gets or sets whether the object is read only.
/// </summary>
@@ -92,7 +92,7 @@ namespace Newtonsoft.Json.Schema
/// Gets or sets the maximum decimals.
/// </summary>
/// <value>The maximum decimals.</value>
public int? MaximumDecimals { get; set; }
public double? DivisibleBy { get; set; }
/// <summary>
/// Gets or sets the minimum.
/// </summary>
@@ -146,8 +146,8 @@ namespace Newtonsoft.Json.Schema
case JsonSchemaConstants.AdditionalPropertiesPropertyName:
ProcessAdditionalProperties();
break;
case JsonSchemaConstants.OptionalPropertyName:
CurrentSchema.Optional = (bool)_reader.Value;
case JsonSchemaConstants.RequiredPropertyName:
CurrentSchema.Required = (bool)_reader.Value;
break;
case JsonSchemaConstants.RequiresPropertyName:
CurrentSchema.Requires = (string) _reader.Value;
@@ -173,8 +173,8 @@ namespace Newtonsoft.Json.Schema
case JsonSchemaConstants.MinimumItemsPropertyName:
CurrentSchema.MinimumItems = Convert.ToInt32(_reader.Value, CultureInfo.InvariantCulture);
break;
case JsonSchemaConstants.MaximumDecimalsPropertyName:
CurrentSchema.MaximumDecimals = Convert.ToInt32(_reader.Value, CultureInfo.InvariantCulture);
case JsonSchemaConstants.DivisibleByPropertyName:
CurrentSchema.DivisibleBy = Convert.ToDouble(_reader.Value, CultureInfo.InvariantCulture);
break;
case JsonSchemaConstants.DisallowPropertyName:
CurrentSchema.Disallow = ProcessType();
@@ -35,7 +35,7 @@ namespace Newtonsoft.Json.Schema
public const string TypePropertyName = "type";
public const string PropertiesPropertyName = "properties";
public const string ItemsPropertyName = "items";
public const string OptionalPropertyName = "optional";
public const string RequiredPropertyName = "required";
public const string AdditionalPropertiesPropertyName = "additionalProperties";
public const string RequiresPropertyName = "requires";
public const string IdentityPropertyName = "identity";
@@ -54,7 +54,7 @@ namespace Newtonsoft.Json.Schema
public const string FormatPropertyName = "format";
public const string DefaultPropertyName = "default";
public const string TransientPropertyName = "transient";
public const string MaximumDecimalsPropertyName = "maxDecimal";
public const string DivisibleByPropertyName = "divisibleBy";
public const string HiddenPropertyName = "hidden";
public const string DisallowPropertyName = "disallow";
public const string ExtendsPropertyName = "extends";
@@ -205,7 +205,7 @@ namespace Newtonsoft.Json.Schema
}
}
private JsonSchema GenerateInternal(Type type, Required valueRequired, bool optional)
private JsonSchema GenerateInternal(Type type, Required valueRequired, bool required)
{
ValidationUtils.ArgumentNotNull(type, "type");
@@ -221,8 +221,8 @@ namespace Newtonsoft.Json.Schema
// change resolved schema to allow nulls. hacky but what are ya gonna do?
if (valueRequired != Required.Always && !HasFlag(resolvedSchema.Type, JsonSchemaType.Null))
resolvedSchema.Type |= JsonSchemaType.Null;
if (optional && resolvedSchema.Optional != true)
resolvedSchema.Optional = true;
if (required && resolvedSchema.Required != true)
resolvedSchema.Required = true;
return resolvedSchema;
}
@@ -248,8 +248,8 @@ namespace Newtonsoft.Json.Schema
if (explicitId != null)
CurrentSchema.Id = explicitId;
if (optional)
CurrentSchema.Optional = true;
if (required)
CurrentSchema.Required = true;
CurrentSchema.Title = GetTitle(type);
CurrentSchema.Description = GetDescription(type);
@@ -364,7 +364,7 @@ namespace Newtonsoft.Json.Schema
property.ShouldSerialize != null ||
property.GetIsSpecified != null;
JsonSchema propertySchema = GenerateInternal(property.PropertyType, property.Required, optional);
JsonSchema propertySchema = GenerateInternal(property.PropertyType, property.Required, !optional);
if (property.DefaultValue != null)
propertySchema.Default = JToken.FromObject(property.DefaultValue);
@@ -33,11 +33,11 @@ namespace Newtonsoft.Json.Schema
{
internal class JsonSchemaModel
{
public bool Optional { get; set; }
public bool Required { get; set; }
public JsonSchemaType Type { get; set; }
public int? MinimumLength { get; set; }
public int? MaximumLength { get; set; }
public int? MaximumDecimals { get; set; }
public double? DivisibleBy { get; set; }
public double? Minimum { get; set; }
public double? Maximum { get; set; }
public int? MinimumItems { get; set; }
@@ -54,7 +54,7 @@ namespace Newtonsoft.Json.Schema
{
Type = JsonSchemaType.Any;
AllowAdditionalProperties = true;
Optional = true;
Required = false;
}
public static JsonSchemaModel Create(IList<JsonSchema> schemata)
@@ -71,12 +71,16 @@ namespace Newtonsoft.Json.Schema
private static void Combine(JsonSchemaModel model, JsonSchema schema)
{
model.Optional = model.Optional && (schema.Optional ?? false);
// Version 3 of the Draft JSON Schema has the default value of Not Required
model.Required = model.Required || (schema.Required ?? false);
model.Type = model.Type & (schema.Type ?? JsonSchemaType.Any);
model.MinimumLength = MathUtils.Max(model.MinimumLength, schema.MinimumLength);
model.MaximumLength = MathUtils.Min(model.MaximumLength, schema.MaximumLength);
model.MaximumDecimals = MathUtils.Min(model.MaximumDecimals, schema.MaximumDecimals);
// not sure what is the best way to combine divisibleBy
model.DivisibleBy = MathUtils.Max(model.DivisibleBy, schema.DivisibleBy);
model.Minimum = MathUtils.Max(model.Minimum, schema.Minimum);
model.Maximum = MathUtils.Max(model.Maximum, schema.Maximum);
model.MinimumItems = MathUtils.Max(model.MinimumItems, schema.MinimumItems);
@@ -70,7 +70,7 @@ namespace Newtonsoft.Json.Schema
WritePropertyIfNotNull(_writer, JsonSchemaConstants.IdPropertyName, schema.Id);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.TitlePropertyName, schema.Title);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.DescriptionPropertyName, schema.Description);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.OptionalPropertyName, schema.Optional);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.RequiredPropertyName, schema.Required);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.ReadOnlyPropertyName, schema.ReadOnly);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.HiddenPropertyName, schema.Hidden);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.TransientPropertyName, schema.Transient);
@@ -107,7 +107,7 @@ namespace Newtonsoft.Json.Schema
WritePropertyIfNotNull(_writer, JsonSchemaConstants.MaximumLengthPropertyName, schema.MaximumLength);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.MinimumItemsPropertyName, schema.MinimumItems);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.MaximumItemsPropertyName, schema.MaximumItems);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.MaximumDecimalsPropertyName, schema.MaximumDecimals);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.DivisibleByPropertyName, schema.DivisibleBy);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.FormatPropertyName, schema.Format);
WritePropertyIfNotNull(_writer, JsonSchemaConstants.PatternPropertyName, schema.Pattern);
if (schema.Enum != null)