Skip to content

Commit

Permalink
Merge pull request #956 from RicoSuter/master
Browse files Browse the repository at this point in the history
Release v9.13.35
  • Loading branch information
RicoSuter authored Apr 21, 2019
2 parents 1f5c905 + e634224 commit 924f3b6
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,36 @@ public void When_name_contains_dash_then_it_is_converted_to_upper_case()
AssertCompile(output);
}

[Theory]
[InlineData("foo@bar", "Foobar")]
[InlineData("foo$bar", "Foobar")]
[InlineData("foobars[]", "Foobars")]
[InlineData("foo.bar", "FooBar")]
[InlineData("foo=bar", "FooBar")]
[InlineData("foo+bar", "Fooplusbar")]
[InlineData("foo*bar", "FooStarbar")]
[InlineData("foo:bar", "Foo_bar")]
public void When_name_contains_unallowed_characters_then_they_are_converted_to_valid_csharp(string jsonPropertyName, string expectedCSharpName)
{
// Arrange
var schema = new JsonSchema4();
schema.Properties[jsonPropertyName] = new JsonProperty
{
Type = JsonObjectType.String
};

var generator = new CSharpGenerator(schema);

// Act
var output = generator.GenerateFile("MyClass");

// Assert
Assert.Contains($@"[Newtonsoft.Json.JsonProperty(""{jsonPropertyName}"", ", output);
Assert.Contains($@"public string {expectedCSharpName}", output);

AssertCompile(output);
}

[Fact]
public void When_type_name_is_missing_then_anonymous_name_is_generated()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public virtual string Generate(JsonProperty property)
.Replace("\"", string.Empty)
.Replace("@", string.Empty)
.Replace("$", string.Empty)
.Replace("[", string.Empty)
.Replace("]", string.Empty)
.Replace(".", "-")
.Replace("=", "-")
.Replace("+", "plus"), true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard1.3;netstandard2.0;net451</TargetFrameworks>
<Description>JSON Schema reader, generator and validator for .NET</Description>
<Version>9.13.34</Version>
<Version>9.13.35</Version>
<PackageTags>json schema validation generator .net</PackageTags>
<Copyright>Copyright © Rico Suter, 2018</Copyright>
<PackageLicenseUrl>https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md</PackageLicenseUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard1.3;netstandard2.0;net451</TargetFrameworks>
<Description>JSON Schema reader, generator and validator for .NET</Description>
<Version>9.13.34</Version>
<Version>9.13.35</Version>
<PackageTags>json schema validation generator .net</PackageTags>
<Copyright>Copyright © Rico Suter, 2018</Copyright>
<PackageLicenseUrl>https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md</PackageLicenseUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard1.3;netstandard2.0;net451</TargetFrameworks>
<Description>JSON Schema reader, generator and validator for .NET</Description>
<Version>9.13.34</Version>
<Version>9.13.35</Version>
<PackageTags>json schema validation generator .net</PackageTags>
<Copyright>Copyright © Rico Suter, 2018</Copyright>
<PackageLicenseUrl>https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md</PackageLicenseUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/NJsonSchema.Yaml/NJsonSchema.Yaml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard1.3;netstandard2.0;net45</TargetFrameworks>
<Description>JSON Schema reader, generator and validator for .NET</Description>
<Version>9.13.34</Version>
<Version>9.13.35</Version>
<PackageTags>json schema validation generator .net</PackageTags>
<Copyright>Copyright © Rico Suter, 2018</Copyright>
<PackageLicenseUrl>https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md</PackageLicenseUrl>
Expand Down
9 changes: 0 additions & 9 deletions src/NJsonSchema/JsonProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

using System.ComponentModel;
using Newtonsoft.Json;
using NJsonSchema.Infrastructure;

namespace NJsonSchema
{
Expand All @@ -17,14 +16,6 @@ public class JsonProperty : JsonSchema4
{
private object _parent;

internal static JsonProperty FromJsonSchema(string name, JsonSchema4 type)
{
var data = JsonConvert.SerializeObject(type, JsonSchemaSerialization.CurrentSerializerSettings);
var property = JsonConvert.DeserializeObject<JsonProperty>(data, JsonSchemaSerialization.CurrentSerializerSettings);
property.Name = name;
return property;
}

/// <summary>Gets or sets the name of the property. </summary>
[JsonIgnore]
public string Name { get; internal set; }
Expand Down
21 changes: 11 additions & 10 deletions src/NJsonSchema/JsonSchema4.Serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,34 +264,34 @@ internal ICollection<string> RequiredPropertiesRaw
}

[JsonProperty("properties", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
internal IDictionary<string, JsonSchema4> PropertiesRaw
internal IDictionary<string, JsonProperty> PropertiesRaw
{
get
{
return Properties != null && Properties.Count > 0 ?
Properties.ToDictionary(p => p.Key, p => (JsonSchema4)p.Value) : null;
Properties.ToDictionary(p => p.Key, p => p.Value) : null;
}
set
{
Properties = value != null ?
new ObservableDictionary<string, JsonProperty>(value.ToDictionary(p => p.Key, p => JsonProperty.FromJsonSchema(p.Key, p.Value))) :
new ObservableDictionary<string, JsonProperty>(value) :
new ObservableDictionary<string, JsonProperty>();
}
}

[JsonProperty("patternProperties", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
internal IDictionary<string, JsonSchema4> PatternPropertiesRaw
internal IDictionary<string, JsonProperty> PatternPropertiesRaw
{
get
{
return PatternProperties != null && PatternProperties.Count > 0 ?
PatternProperties.ToDictionary(p => p.Key, p => (JsonSchema4)p.Value) : null;
PatternProperties.ToDictionary(p => p.Key, p => p.Value) : null;
}
set
{
PatternProperties = value != null ?
new ObservableDictionary<string, JsonSchema4>(value.ToDictionary(p => p.Key, p => p.Value)) :
new ObservableDictionary<string, JsonSchema4>();
new ObservableDictionary<string, JsonProperty>(value) :
new ObservableDictionary<string, JsonProperty>();
}
}

Expand Down Expand Up @@ -350,14 +350,15 @@ private void RegisterProperties(IDictionary<string, JsonProperty> oldCollection,
}
}

private void RegisterSchemaDictionary(IDictionary<string, JsonSchema4> oldCollection, IDictionary<string, JsonSchema4> newCollection)
private void RegisterSchemaDictionary<T>(IDictionary<string, T> oldCollection, IDictionary<string, T> newCollection)
where T : JsonSchema4
{
if (oldCollection != null)
((ObservableDictionary<string, JsonSchema4>)oldCollection).CollectionChanged -= InitializeSchemaCollection;
((ObservableDictionary<string, T>)oldCollection).CollectionChanged -= InitializeSchemaCollection;

if (newCollection != null)
{
((ObservableDictionary<string, JsonSchema4>)newCollection).CollectionChanged += InitializeSchemaCollection;
((ObservableDictionary<string, T>)newCollection).CollectionChanged += InitializeSchemaCollection;
InitializeSchemaCollection(newCollection, null);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/NJsonSchema/JsonSchema4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public partial class JsonSchema4 : IDocumentPathProvider
() => CreateJsonSerializerContractResolver(SerializationSchemaType));

private IDictionary<string, JsonProperty> _properties;
private IDictionary<string, JsonSchema4> _patternProperties;
private IDictionary<string, JsonProperty> _patternProperties;
private IDictionary<string, JsonSchema4> _definitions;

private ICollection<JsonSchema4> _allOf;
Expand Down Expand Up @@ -494,7 +494,7 @@ public JsonXmlObject Xml

/// <summary>Gets the pattern properties of the type. </summary>
[JsonIgnore]
public IDictionary<string, JsonSchema4> PatternProperties
public IDictionary<string, JsonProperty> PatternProperties
{
get { return _patternProperties; }
internal set
Expand Down Expand Up @@ -846,7 +846,7 @@ private void Initialize()
Properties = new ObservableDictionary<string, JsonProperty>();

if (PatternProperties == null)
PatternProperties = new ObservableDictionary<string, JsonSchema4>();
PatternProperties = new ObservableDictionary<string, JsonProperty>();

if (Definitions == null)
Definitions = new ObservableDictionary<string, JsonSchema4>();
Expand Down
2 changes: 1 addition & 1 deletion src/NJsonSchema/NJsonSchema.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard1.0;netstandard2.0;net40;net45</TargetFrameworks>
<Description>JSON Schema reader, generator and validator for .NET</Description>
<Version>9.13.34</Version>
<Version>9.13.35</Version>
<PackageTags>json schema validation generator .net</PackageTags>
<Copyright>Copyright © Rico Suter, 2018</Copyright>
<PackageLicenseUrl>https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md</PackageLicenseUrl>
Expand Down

0 comments on commit 924f3b6

Please sign in to comment.