Skip to content

Commit

Permalink
enum
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasnordqvist committed Nov 10, 2024
1 parent 242de30 commit 4da294c
Show file tree
Hide file tree
Showing 20 changed files with 686 additions and 252 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
using DotNetThoughts.Results;
using System.Text.Json;
using static FartingUnicorn.MapperOptions;

namespace FartingUnicorn.Generated;

public static partial class Mappers
{
public static Result<FartingUnicorn.Benchmarks.UserProfile> MapToFartingUnicorn_Benchmarks_UserProfile(JsonElement jsonElement, string[] path = null)
public static Result<FartingUnicorn.Benchmarks.UserProfile> MapToFartingUnicorn_Benchmarks_UserProfile(JsonElement jsonElement, MapperOptions mapperOptions = null, string[] path = null)
{
if(path is null)
if (mapperOptions is null)
{
mapperOptions = new MapperOptions();
}
if (path is null)
{
path = ["$"];
}
/*object*/
if (jsonElement.ValueKind != JsonValueKind.Object)
{
if (jsonElement.ValueKind != JsonValueKind.Object)
{
return Result<FartingUnicorn.Benchmarks.UserProfile>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
return Result<FartingUnicorn.Benchmarks.UserProfile>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
var obj = new FartingUnicorn.Benchmarks.UserProfile();

List<IError> errors = new();
var isNamePropertyDefined = jsonElement.TryGetProperty("Name", out var jsonNameProperty);
if (isNamePropertyDefined)
{
// type = String, isOption = False, isNullable = False
// type = System.String, isOption = False, isNullable = False
if (jsonNameProperty.ValueKind == JsonValueKind.Null)
{
errors.Add(new RequiredValueMissingError([.. path, "Name"]));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
using DotNetThoughts.Results;
using System.Text.Json;
using static FartingUnicorn.MapperOptions;

namespace FartingUnicorn.Generated;

public static partial class Mappers
{
public static Result<FartingUnicorn.Tests.SingleField.BoolType.NonNullableNonOptional_Tests.BlogPost> MapToFartingUnicorn_Tests_SingleField_BoolType_NonNullableNonOptional_Tests_BlogPost(JsonElement jsonElement, string[] path = null)
public static Result<FartingUnicorn.Tests.SingleField.BoolType.NonNullableNonOptional_Tests.BlogPost> MapToFartingUnicorn_Tests_SingleField_BoolType_NonNullableNonOptional_Tests_BlogPost(JsonElement jsonElement, MapperOptions mapperOptions = null, string[] path = null)
{
if(path is null)
if (mapperOptions is null)
{
mapperOptions = new MapperOptions();
}
if (path is null)
{
path = ["$"];
}
/*object*/
if (jsonElement.ValueKind != JsonValueKind.Object)
{
if (jsonElement.ValueKind != JsonValueKind.Object)
{
return Result<FartingUnicorn.Tests.SingleField.BoolType.NonNullableNonOptional_Tests.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
return Result<FartingUnicorn.Tests.SingleField.BoolType.NonNullableNonOptional_Tests.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
var obj = new FartingUnicorn.Tests.SingleField.BoolType.NonNullableNonOptional_Tests.BlogPost();

List<IError> errors = new();
var isIsDraftPropertyDefined = jsonElement.TryGetProperty("IsDraft", out var jsonIsDraftProperty);
if (isIsDraftPropertyDefined)
{
// type = Boolean, isOption = False, isNullable = False
// type = System.Boolean, isOption = False, isNullable = False
if (jsonIsDraftProperty.ValueKind == JsonValueKind.Null)
{
errors.Add(new RequiredValueMissingError([.. path, "IsDraft"]));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
using DotNetThoughts.Results;
using System.Text.Json;
using static FartingUnicorn.MapperOptions;

namespace FartingUnicorn.Generated;

public static partial class Mappers
{
public static Result<FartingUnicorn.Tests.SingleField.BoolType.NonNullableOptional_Tests.BlogPost> MapToFartingUnicorn_Tests_SingleField_BoolType_NonNullableOptional_Tests_BlogPost(JsonElement jsonElement, string[] path = null)
public static Result<FartingUnicorn.Tests.SingleField.BoolType.NonNullableOptional_Tests.BlogPost> MapToFartingUnicorn_Tests_SingleField_BoolType_NonNullableOptional_Tests_BlogPost(JsonElement jsonElement, MapperOptions mapperOptions = null, string[] path = null)
{
if(path is null)
if (mapperOptions is null)
{
mapperOptions = new MapperOptions();
}
if (path is null)
{
path = ["$"];
}
/*object*/
if (jsonElement.ValueKind != JsonValueKind.Object)
{
if (jsonElement.ValueKind != JsonValueKind.Object)
{
return Result<FartingUnicorn.Tests.SingleField.BoolType.NonNullableOptional_Tests.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
return Result<FartingUnicorn.Tests.SingleField.BoolType.NonNullableOptional_Tests.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
var obj = new FartingUnicorn.Tests.SingleField.BoolType.NonNullableOptional_Tests.BlogPost();

List<IError> errors = new();
var isIsDraftPropertyDefined = jsonElement.TryGetProperty("IsDraft", out var jsonIsDraftProperty);
if (isIsDraftPropertyDefined)
{
// type = Boolean, isOption = True, isNullable = False
// type = System.Boolean, isOption = True, isNullable = False
if (jsonIsDraftProperty.ValueKind == JsonValueKind.Null)
{
obj.IsDraft = new None<Boolean>();
obj.IsDraft = new None<System.Boolean>();
}
else if (jsonIsDraftProperty.ValueKind == JsonValueKind.True || jsonIsDraftProperty.ValueKind == JsonValueKind.False)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
using DotNetThoughts.Results;
using System.Text.Json;
using static FartingUnicorn.MapperOptions;

namespace FartingUnicorn.Generated;

public static partial class Mappers
{
public static Result<FartingUnicorn.Tests.SingleField.BoolType.NullableNonOptional_Tests.BlogPost> MapToFartingUnicorn_Tests_SingleField_BoolType_NullableNonOptional_Tests_BlogPost(JsonElement jsonElement, string[] path = null)
public static Result<FartingUnicorn.Tests.SingleField.BoolType.NullableNonOptional_Tests.BlogPost> MapToFartingUnicorn_Tests_SingleField_BoolType_NullableNonOptional_Tests_BlogPost(JsonElement jsonElement, MapperOptions mapperOptions = null, string[] path = null)
{
if(path is null)
if (mapperOptions is null)
{
mapperOptions = new MapperOptions();
}
if (path is null)
{
path = ["$"];
}
/*object*/
if (jsonElement.ValueKind != JsonValueKind.Object)
{
if (jsonElement.ValueKind != JsonValueKind.Object)
{
return Result<FartingUnicorn.Tests.SingleField.BoolType.NullableNonOptional_Tests.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
return Result<FartingUnicorn.Tests.SingleField.BoolType.NullableNonOptional_Tests.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
var obj = new FartingUnicorn.Tests.SingleField.BoolType.NullableNonOptional_Tests.BlogPost();

List<IError> errors = new();
var isIsDraftPropertyDefined = jsonElement.TryGetProperty("IsDraft", out var jsonIsDraftProperty);
if (isIsDraftPropertyDefined)
{
// type = Boolean, isOption = False, isNullable = True
// type = System.Boolean, isOption = False, isNullable = True
if (jsonIsDraftProperty.ValueKind == JsonValueKind.Null)
{
errors.Add(new RequiredValueMissingError([.. path, "IsDraft"]));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
using DotNetThoughts.Results;
using System.Text.Json;
using static FartingUnicorn.MapperOptions;

namespace FartingUnicorn.Generated;

public static partial class Mappers
{
public static Result<FartingUnicorn.Tests.SingleField.BoolType.NullableOptional_Tests.BlogPost> MapToFartingUnicorn_Tests_SingleField_BoolType_NullableOptional_Tests_BlogPost(JsonElement jsonElement, string[] path = null)
public static Result<FartingUnicorn.Tests.SingleField.BoolType.NullableOptional_Tests.BlogPost> MapToFartingUnicorn_Tests_SingleField_BoolType_NullableOptional_Tests_BlogPost(JsonElement jsonElement, MapperOptions mapperOptions = null, string[] path = null)
{
if(path is null)
if (mapperOptions is null)
{
mapperOptions = new MapperOptions();
}
if (path is null)
{
path = ["$"];
}
/*object*/
if (jsonElement.ValueKind != JsonValueKind.Object)
{
if (jsonElement.ValueKind != JsonValueKind.Object)
{
return Result<FartingUnicorn.Tests.SingleField.BoolType.NullableOptional_Tests.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
return Result<FartingUnicorn.Tests.SingleField.BoolType.NullableOptional_Tests.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
var obj = new FartingUnicorn.Tests.SingleField.BoolType.NullableOptional_Tests.BlogPost();

List<IError> errors = new();
var isIsDraftPropertyDefined = jsonElement.TryGetProperty("IsDraft", out var jsonIsDraftProperty);
if (isIsDraftPropertyDefined)
{
// type = Boolean, isOption = True, isNullable = True
// type = System.Boolean, isOption = True, isNullable = True
if (jsonIsDraftProperty.ValueKind == JsonValueKind.Null)
{
obj.IsDraft = new None<Boolean>();
obj.IsDraft = new None<System.Boolean>();
}
else if (jsonIsDraftProperty.ValueKind == JsonValueKind.True || jsonIsDraftProperty.ValueKind == JsonValueKind.False)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using DotNetThoughts.Results;
using System.Text.Json;
using static FartingUnicorn.MapperOptions;

namespace FartingUnicorn.Generated;

public static partial class Mappers
{
public static Result<FartingUnicorn.Tests.SingleField.EnumType.NonNullableNonOptional_Tests.BlogPost> MapToFartingUnicorn_Tests_SingleField_EnumType_NonNullableNonOptional_Tests_BlogPost(JsonElement jsonElement, MapperOptions mapperOptions = null, string[] path = null)
{
if (mapperOptions is null)
{
mapperOptions = new MapperOptions();
}
if (path is null)
{
path = ["$"];
}
if (jsonElement.ValueKind != JsonValueKind.Object)
{
return Result<FartingUnicorn.Tests.SingleField.EnumType.NonNullableNonOptional_Tests.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
var obj = new FartingUnicorn.Tests.SingleField.EnumType.NonNullableNonOptional_Tests.BlogPost();

List<IError> errors = new();
var isStatusPropertyDefined = jsonElement.TryGetProperty("Status", out var jsonStatusProperty);
if (isStatusPropertyDefined)
{
// type = FartingUnicorn.Tests.SingleField.EnumType.NonNullableNonOptional_Tests.BlogPost.BlogPostStatus, isOption = False, isNullable = False
if (jsonStatusProperty.ValueKind == JsonValueKind.Null)
{
errors.Add(new RequiredValueMissingError([.. path, "Status"]));
}
if (mapperOptions.TryGetConverter(typeof(FartingUnicorn.Tests.SingleField.EnumType.NonNullableNonOptional_Tests.BlogPost.BlogPostStatus), out IConverter customConverter))
{
if (jsonStatusProperty.ValueKind != customConverter.ExpectedJsonValueKind)
{
errors.Add(new ValueHasWrongTypeError(path, customConverter.ExpectedJsonValueKind.ToString(), jsonStatusProperty.ValueKind.ToString()));
}
var result = customConverter.Convert(typeof(FartingUnicorn.Tests.SingleField.EnumType.NonNullableNonOptional_Tests.BlogPost.BlogPostStatus), jsonStatusProperty, mapperOptions, path);
if (result.Success)
{
obj.Status = result.Map(x => (FartingUnicorn.Tests.SingleField.EnumType.NonNullableNonOptional_Tests.BlogPost.BlogPostStatus)x).Value;
}
else
{
errors.AddRange(result.Errors.Select(x => new MappingError(path, x.Message)).ToArray());
}
}
}
else
{
errors.Add(new RequiredPropertyMissingError([.. path, "Status"]));
}
if(errors.Any())
{
return Result<FartingUnicorn.Tests.SingleField.EnumType.NonNullableNonOptional_Tests.BlogPost>.Error(errors);
}
if(false)/*check if is option*/
{
}
else
{
return Result<FartingUnicorn.Tests.SingleField.EnumType.NonNullableNonOptional_Tests.BlogPost>.Ok(obj);
}
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
using DotNetThoughts.Results;
using System.Text.Json;
using static FartingUnicorn.MapperOptions;

namespace FartingUnicorn.Generated;

public static partial class Mappers
{
public static Result<FartingUnicorn.Tests.SingleField.IntType.NonNullableNonOptional_Tests.BlogPost> MapToFartingUnicorn_Tests_SingleField_IntType_NonNullableNonOptional_Tests_BlogPost(JsonElement jsonElement, string[] path = null)
public static Result<FartingUnicorn.Tests.SingleField.IntType.NonNullableNonOptional_Tests.BlogPost> MapToFartingUnicorn_Tests_SingleField_IntType_NonNullableNonOptional_Tests_BlogPost(JsonElement jsonElement, MapperOptions mapperOptions = null, string[] path = null)
{
if(path is null)
if (mapperOptions is null)
{
mapperOptions = new MapperOptions();
}
if (path is null)
{
path = ["$"];
}
/*object*/
if (jsonElement.ValueKind != JsonValueKind.Object)
{
if (jsonElement.ValueKind != JsonValueKind.Object)
{
return Result<FartingUnicorn.Tests.SingleField.IntType.NonNullableNonOptional_Tests.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
return Result<FartingUnicorn.Tests.SingleField.IntType.NonNullableNonOptional_Tests.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
var obj = new FartingUnicorn.Tests.SingleField.IntType.NonNullableNonOptional_Tests.BlogPost();

List<IError> errors = new();
var isRatingPropertyDefined = jsonElement.TryGetProperty("Rating", out var jsonRatingProperty);
if (isRatingPropertyDefined)
{
// type = Int32, isOption = False, isNullable = False
// type = System.Int32, isOption = False, isNullable = False
if (jsonRatingProperty.ValueKind == JsonValueKind.Null)
{
errors.Add(new RequiredValueMissingError([.. path, "Rating"]));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
using DotNetThoughts.Results;
using System.Text.Json;
using static FartingUnicorn.MapperOptions;

namespace FartingUnicorn.Generated;

public static partial class Mappers
{
public static Result<FartingUnicorn.Tests.SingleField.IntType.NonNullableOptional_Tests.BlogPost> MapToFartingUnicorn_Tests_SingleField_IntType_NonNullableOptional_Tests_BlogPost(JsonElement jsonElement, string[] path = null)
public static Result<FartingUnicorn.Tests.SingleField.IntType.NonNullableOptional_Tests.BlogPost> MapToFartingUnicorn_Tests_SingleField_IntType_NonNullableOptional_Tests_BlogPost(JsonElement jsonElement, MapperOptions mapperOptions = null, string[] path = null)
{
if(path is null)
if (mapperOptions is null)
{
mapperOptions = new MapperOptions();
}
if (path is null)
{
path = ["$"];
}
/*object*/
if (jsonElement.ValueKind != JsonValueKind.Object)
{
if (jsonElement.ValueKind != JsonValueKind.Object)
{
return Result<FartingUnicorn.Tests.SingleField.IntType.NonNullableOptional_Tests.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
return Result<FartingUnicorn.Tests.SingleField.IntType.NonNullableOptional_Tests.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
var obj = new FartingUnicorn.Tests.SingleField.IntType.NonNullableOptional_Tests.BlogPost();

List<IError> errors = new();
var isRatingPropertyDefined = jsonElement.TryGetProperty("Rating", out var jsonRatingProperty);
if (isRatingPropertyDefined)
{
// type = Int32, isOption = True, isNullable = False
// type = System.Int32, isOption = True, isNullable = False
if (jsonRatingProperty.ValueKind == JsonValueKind.Null)
{
obj.Rating = new None<Int32>();
obj.Rating = new None<System.Int32>();
}
else if (jsonRatingProperty.ValueKind == JsonValueKind.Number)
{
Expand Down
Loading

0 comments on commit 4da294c

Please sign in to comment.