Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,32 @@ public async Task When_property_has_same_name_as_class_then_it_is_renamed()
CSharpCompiler.AssertCompile(code);
}

[Fact]
public async Task When_property_has_same_name_as_class_and_suffixed_name_is_taken_then_it_is_renamed_without_infinite_loop()
{
// Arrange
var schemaJson = @"{
""type"": ""object"",
""properties"": {
""Foo"": {
""type"": ""string""
},
""Foo1"": {
""type"": ""string""
}
}
}";
var schema = await JsonSchema.FromJsonAsync(schemaJson);

// Act
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings { ClassStyle = CSharpClassStyle.Poco });
var code = generator.GenerateFile("Foo");

// Assert
await VerifyHelper.Verify(code);
CSharpCompiler.AssertCompile(code);
}

[Fact]
public async Task When_patternProperties_is_set_with_string_value_type_then_correct_dictionary_is_generated()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//----------------------
// <auto-generated>
// </auto-generated>
//----------------------


namespace MyNamespace
{
#pragma warning disable // Disable all warnings

public partial class Foo
{

[Newtonsoft.Json.JsonProperty("Foo", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string Foo2 { get; set; }

[Newtonsoft.Json.JsonProperty("Foo1", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string Foo1 { get; set; }

private System.Collections.Generic.IDictionary<string, object> _additionalProperties;

[Newtonsoft.Json.JsonExtensionData]
public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
{
get { return _additionalProperties ?? (_additionalProperties = new System.Collections.Generic.Dictionary<string, object>()); }
set { _additionalProperties = value; }
}

}
}
1 change: 1 addition & 0 deletions src/NJsonSchema.CodeGeneration.CSharp/CSharpGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ private static void RenamePropertyWithSameNameAsClass(string typeName, List<Prop
while (properties.Exists(p => p.PropertyName == candidate))
{
number++;
candidate = typeName + number;
}

propertyWithSameNameAsClass.PropertyName += number;
Expand Down