Skip to content
Open
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 @@ -480,5 +480,26 @@ public async Task When_array_property_has_minitems_then_minlength_attribute_is_r
Assert.Contains("[System.ComponentModel.DataAnnotations.MinLength(10)]\n" +
" public System.Collections.Generic.ICollection<string> Value { get; set; } = new System.Collections.ObjectModel.Collection<string>();\n", code);
}

[Fact]
public async Task When_date_time_property_has_min_max_length_then_no_string_length_attribute_is_generated()
{
var json = @"{
'type': 'object',
'properties': {
'myDateTime': {
'type': 'string',
'format': 'date-time',
'minLength': 1,
'maxLength': 50
}
}
}";
var schema = await JsonSchema.FromJsonAsync(json);
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings { ClassStyle = CSharpClassStyle.Poco });
var code = generator.GenerateFile();

Assert.DoesNotContain("StringLength", code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ public bool RenderStringLengthAttribute
}

return _property.ActualTypeSchema.Type.IsString() &&
(_property.ActualSchema.MinLength.HasValue || _property.ActualSchema.MaxLength.HasValue);
(_property.ActualSchema.MinLength.HasValue || _property.ActualSchema.MaxLength.HasValue) &&
_property.ActualSchema.Format is not JsonFormatStrings.DateTime
and not JsonFormatStrings.Date
and not JsonFormatStrings.Time;
}
}

Expand Down