Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix output of JsonIgnore attributes #1522

Merged
merged 6 commits into from
Aug 15, 2022
Merged
Changes from 1 commit
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
24 changes: 17 additions & 7 deletions src/NJsonSchema.CodeGeneration.CSharp/Models/PropertyModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ namespace NJsonSchema.CodeGeneration.CSharp.Models
/// <summary>The CSharp property template model.</summary>
public class PropertyModel : PropertyModelBase
{
private readonly static string[] ValueTypeFormats = {
JsonFormatStrings.Date,
JsonFormatStrings.DateTime,
JsonFormatStrings.Time,
JsonFormatStrings.Duration,
JsonFormatStrings.Guid
};
private readonly JsonSchemaProperty _property;
private readonly CSharpGeneratorSettings _settings;
private readonly CSharpTypeResolver _resolver;
Expand Down Expand Up @@ -86,15 +93,18 @@ public string JsonIgnoreCondition

bool IsValueType()
{
var valueTypeFormats = new string[] { "date", "date-time", "uuid" };
return _property.ActualTypeSchema.Type switch
var type = _property.ActualTypeSchema.Type;
if (type.IsBoolean() || type.IsInteger() || type.IsNumber())
{
JsonObjectType.Boolean => true,
JsonObjectType.Integer => true,
JsonObjectType.Number => true,
JsonObjectType.String => valueTypeFormats.Contains(_property.Format),
_ => false,
return true;
}

if (type.IsString())
{
return ValueTypeFormats.Contains(_property.Format);
AroglDarthu marked this conversation as resolved.
Show resolved Hide resolved
};

return false;
}
}
}
Expand Down