Skip to content

Commit

Permalink
make all properties nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Mar 8, 2024
1 parent 1d6181c commit 61fceee
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 97 deletions.
2 changes: 1 addition & 1 deletion src/Generator/CSharp.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function writeStruct(Code\Name $name, array $properties, ?string $exte
foreach ($properties as $property) {
/** @var Code\Property $property */
$code.= $this->indent . '[JsonPropertyName("' . $property->getName()->getRaw() . '")]' . "\n";
$code.= $this->indent . 'public ' . $property->getType() . ' ' . $property->getName()->getProperty() . ' { get; set; }' . "\n";
$code.= $this->indent . 'public ' . $property->getType() . '? ' . $property->getName()->getProperty() . ' { get; set; }' . "\n";
}

$code.= '}' . "\n";
Expand Down
70 changes: 35 additions & 35 deletions tests/Generator/resource/csharp/csharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
public class Location
{
[JsonPropertyName("lat")]
public double Lat { get; set; }
public double? Lat { get; set; }
[JsonPropertyName("long")]
public double Long { get; set; }
public double? Long { get; set; }
}

using System.Text.Json.Serialization;
Expand All @@ -19,9 +19,9 @@ public class Location
public class Web
{
[JsonPropertyName("name")]
public string Name { get; set; }
public string? Name { get; set; }
[JsonPropertyName("url")]
public string Url { get; set; }
public string? Url { get; set; }
}

using System.Text.Json.Serialization;
Expand All @@ -32,15 +32,15 @@ public class Web
public class Author
{
[JsonPropertyName("title")]
public string Title { get; set; }
public string? Title { get; set; }
[JsonPropertyName("email")]
public string Email { get; set; }
public string? Email { get; set; }
[JsonPropertyName("categories")]
public List<string> Categories { get; set; }
public List<string>? Categories { get; set; }
[JsonPropertyName("locations")]
public List<Location> Locations { get; set; }
public List<Location>? Locations { get; set; }
[JsonPropertyName("origin")]
public Location Origin { get; set; }
public Location? Origin { get; set; }
}

using System.Text.Json.Serialization;
Expand All @@ -58,55 +58,55 @@ public class Meta : Dictionary<string, string>
public class News
{
[JsonPropertyName("config")]
public Meta Config { get; set; }
public Meta? Config { get; set; }
[JsonPropertyName("inlineConfig")]
public Dictionary<string, string> InlineConfig { get; set; }
public Dictionary<string, string>? InlineConfig { get; set; }
[JsonPropertyName("mapTags")]
public Dictionary<string, string> MapTags { get; set; }
public Dictionary<string, string>? MapTags { get; set; }
[JsonPropertyName("mapReceiver")]
public Dictionary<string, Author> MapReceiver { get; set; }
public Dictionary<string, Author>? MapReceiver { get; set; }
[JsonPropertyName("mapResources")]
public Dictionary<string, object> MapResources { get; set; }
public Dictionary<string, object>? MapResources { get; set; }
[JsonPropertyName("tags")]
public List<string> Tags { get; set; }
public List<string>? Tags { get; set; }
[JsonPropertyName("receiver")]
public List<Author> Receiver { get; set; }
public List<Author>? Receiver { get; set; }
[JsonPropertyName("resources")]
public List<object> Resources { get; set; }
public List<object>? Resources { get; set; }
[JsonPropertyName("profileImage")]
public byte[] ProfileImage { get; set; }
public byte[]? ProfileImage { get; set; }
[JsonPropertyName("read")]
public bool Read { get; set; }
public bool? Read { get; set; }
[JsonPropertyName("source")]
public object Source { get; set; }
public object? Source { get; set; }
[JsonPropertyName("author")]
public Author Author { get; set; }
public Author? Author { get; set; }
[JsonPropertyName("meta")]
public Meta Meta { get; set; }
public Meta? Meta { get; set; }
[JsonPropertyName("sendDate")]
public DateOnly SendDate { get; set; }
public DateOnly? SendDate { get; set; }
[JsonPropertyName("readDate")]
public DateTime ReadDate { get; set; }
public DateTime? ReadDate { get; set; }
[JsonPropertyName("expires")]
public TimeSpan Expires { get; set; }
public TimeSpan? Expires { get; set; }
[JsonPropertyName("range")]
public TimeSpan Range { get; set; }
public TimeSpan? Range { get; set; }
[JsonPropertyName("price")]
public double Price { get; set; }
public double? Price { get; set; }
[JsonPropertyName("rating")]
public int Rating { get; set; }
public int? Rating { get; set; }
[JsonPropertyName("content")]
public string Content { get; set; }
public string? Content { get; set; }
[JsonPropertyName("question")]
public string Question { get; set; }
public string? Question { get; set; }
[JsonPropertyName("version")]
public string Version { get; set; }
public string? Version { get; set; }
[JsonPropertyName("coffeeTime")]
public TimeOnly CoffeeTime { get; set; }
public TimeOnly? CoffeeTime { get; set; }
[JsonPropertyName("profileUri")]
public Uri ProfileUri { get; set; }
public Uri? ProfileUri { get; set; }
[JsonPropertyName("g-recaptcha-response")]
public string Captcha { get; set; }
public string? Captcha { get; set; }
[JsonPropertyName("payload")]
public object Payload { get; set; }
public object? Payload { get; set; }
}
92 changes: 46 additions & 46 deletions tests/Generator/resource/csharp/csharp_complex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
public class CommonType
{
[JsonPropertyName("description")]
public string Description { get; set; }
public string? Description { get; set; }
[JsonPropertyName("type")]
public string Type { get; set; }
public string? Type { get; set; }
[JsonPropertyName("nullable")]
public bool Nullable { get; set; }
public bool? Nullable { get; set; }
[JsonPropertyName("deprecated")]
public bool Deprecated { get; set; }
public bool? Deprecated { get; set; }
[JsonPropertyName("readonly")]
public bool Readonly { get; set; }
public bool? Readonly { get; set; }
}

using System.Text.Json.Serialization;
Expand All @@ -25,7 +25,7 @@ public class CommonType
public class AnyType : CommonType
{
[JsonPropertyName("type")]
public string Type { get; set; }
public string? Type { get; set; }
}

using System.Text.Json.Serialization;
Expand All @@ -36,13 +36,13 @@ public class AnyType : CommonType
public class ArrayType : CommonType
{
[JsonPropertyName("type")]
public string Type { get; set; }
public string? Type { get; set; }
[JsonPropertyName("items")]
public object Items { get; set; }
public object? Items { get; set; }
[JsonPropertyName("maxItems")]
public int MaxItems { get; set; }
public int? MaxItems { get; set; }
[JsonPropertyName("minItems")]
public int MinItems { get; set; }
public int? MinItems { get; set; }
}

using System.Text.Json.Serialization;
Expand All @@ -53,11 +53,11 @@ public class ArrayType : CommonType
public class ScalarType : CommonType
{
[JsonPropertyName("format")]
public string Format { get; set; }
public string? Format { get; set; }
[JsonPropertyName("enum")]
public List<object> Enum { get; set; }
public List<object>? Enum { get; set; }
[JsonPropertyName("default")]
public object Default { get; set; }
public object? Default { get; set; }
}

using System.Text.Json.Serialization;
Expand All @@ -68,7 +68,7 @@ public class ScalarType : CommonType
public class BooleanType : ScalarType
{
[JsonPropertyName("type")]
public string Type { get; set; }
public string? Type { get; set; }
}

using System.Text.Json.Serialization;
Expand All @@ -80,9 +80,9 @@ public class BooleanType : ScalarType
public class Discriminator
{
[JsonPropertyName("propertyName")]
public string PropertyName { get; set; }
public string? PropertyName { get; set; }
[JsonPropertyName("mapping")]
public Dictionary<string, string> Mapping { get; set; }
public Dictionary<string, string>? Mapping { get; set; }
}

using System.Text.Json.Serialization;
Expand All @@ -93,7 +93,7 @@ public class Discriminator
public class GenericType
{
[JsonPropertyName("$generic")]
public string Generic { get; set; }
public string? Generic { get; set; }
}

using System.Text.Json.Serialization;
Expand All @@ -104,9 +104,9 @@ public class GenericType
public class IntersectionType
{
[JsonPropertyName("description")]
public string Description { get; set; }
public string? Description { get; set; }
[JsonPropertyName("allOf")]
public List<ReferenceType> AllOf { get; set; }
public List<ReferenceType>? AllOf { get; set; }
}

using System.Text.Json.Serialization;
Expand All @@ -117,13 +117,13 @@ public class IntersectionType
public class MapType : CommonType
{
[JsonPropertyName("type")]
public string Type { get; set; }
public string? Type { get; set; }
[JsonPropertyName("additionalProperties")]
public object AdditionalProperties { get; set; }
public object? AdditionalProperties { get; set; }
[JsonPropertyName("maxProperties")]
public int MaxProperties { get; set; }
public int? MaxProperties { get; set; }
[JsonPropertyName("minProperties")]
public int MinProperties { get; set; }
public int? MinProperties { get; set; }
}

using System.Text.Json.Serialization;
Expand All @@ -134,17 +134,17 @@ public class MapType : CommonType
public class NumberType : ScalarType
{
[JsonPropertyName("type")]
public string Type { get; set; }
public string? Type { get; set; }
[JsonPropertyName("multipleOf")]
public double MultipleOf { get; set; }
public double? MultipleOf { get; set; }
[JsonPropertyName("maximum")]
public double Maximum { get; set; }
public double? Maximum { get; set; }
[JsonPropertyName("exclusiveMaximum")]
public bool ExclusiveMaximum { get; set; }
public bool? ExclusiveMaximum { get; set; }
[JsonPropertyName("minimum")]
public double Minimum { get; set; }
public double? Minimum { get; set; }
[JsonPropertyName("exclusiveMinimum")]
public bool ExclusiveMinimum { get; set; }
public bool? ExclusiveMinimum { get; set; }
}

using System.Text.Json.Serialization;
Expand All @@ -156,9 +156,9 @@ public class NumberType : ScalarType
public class ReferenceType
{
[JsonPropertyName("$ref")]
public string Ref { get; set; }
public string? Ref { get; set; }
[JsonPropertyName("$template")]
public Dictionary<string, string> Template { get; set; }
public Dictionary<string, string>? Template { get; set; }
}

using System.Text.Json.Serialization;
Expand All @@ -169,13 +169,13 @@ public class ReferenceType
public class StringType : ScalarType
{
[JsonPropertyName("type")]
public string Type { get; set; }
public string? Type { get; set; }
[JsonPropertyName("maxLength")]
public int MaxLength { get; set; }
public int? MaxLength { get; set; }
[JsonPropertyName("minLength")]
public int MinLength { get; set; }
public int? MinLength { get; set; }
[JsonPropertyName("pattern")]
public string Pattern { get; set; }
public string? Pattern { get; set; }
}

using System.Text.Json.Serialization;
Expand All @@ -187,15 +187,15 @@ public class StringType : ScalarType
public class StructType : CommonType
{
[JsonPropertyName("$final")]
public bool Final { get; set; }
public bool? Final { get; set; }
[JsonPropertyName("$extends")]
public string Extends { get; set; }
public string? Extends { get; set; }
[JsonPropertyName("type")]
public string Type { get; set; }
public string? Type { get; set; }
[JsonPropertyName("properties")]
public Dictionary<string, object> Properties { get; set; }
public Dictionary<string, object>? Properties { get; set; }
[JsonPropertyName("required")]
public List<string> Required { get; set; }
public List<string>? Required { get; set; }
}

using System.Text.Json.Serialization;
Expand All @@ -207,11 +207,11 @@ public class StructType : CommonType
public class TypeSchema
{
[JsonPropertyName("$import")]
public Dictionary<string, string> Import { get; set; }
public Dictionary<string, string>? Import { get; set; }
[JsonPropertyName("definitions")]
public Dictionary<string, object> Definitions { get; set; }
public Dictionary<string, object>? Definitions { get; set; }
[JsonPropertyName("$ref")]
public string Ref { get; set; }
public string? Ref { get; set; }
}

using System.Text.Json.Serialization;
Expand All @@ -222,9 +222,9 @@ public class TypeSchema
public class UnionType
{
[JsonPropertyName("description")]
public string Description { get; set; }
public string? Description { get; set; }
[JsonPropertyName("discriminator")]
public Discriminator Discriminator { get; set; }
public Discriminator? Discriminator { get; set; }
[JsonPropertyName("oneOf")]
public List<object> OneOf { get; set; }
public List<object>? OneOf { get; set; }
}
4 changes: 2 additions & 2 deletions tests/Generator/resource/csharp/csharp_import.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
public class Import
{
[JsonPropertyName("students")]
public StudentMap Students { get; set; }
public StudentMap? Students { get; set; }
[JsonPropertyName("student")]
public Student Student { get; set; }
public Student? Student { get; set; }
}

using System.Text.Json.Serialization;
Expand Down
4 changes: 2 additions & 2 deletions tests/Generator/resource/csharp/csharp_import_ns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ namespace Foo.Bar;
public class Import
{
[JsonPropertyName("students")]
public My.Import.StudentMap Students { get; set; }
public My.Import.StudentMap? Students { get; set; }
[JsonPropertyName("student")]
public My.Import.Student Student { get; set; }
public My.Import.Student? Student { get; set; }
}

using System.Text.Json.Serialization;
Expand Down
Loading

0 comments on commit 61fceee

Please sign in to comment.