Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasnordqvist committed Nov 10, 2024
1 parent ffa1ea3 commit 242de30
Show file tree
Hide file tree
Showing 6 changed files with 541 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using DotNetThoughts.Results;
using System.Text.Json;

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)
{
if(path is null)
{
path = ["$"];
}
/*object*/
{
if (jsonElement.ValueKind != JsonValueKind.Object)
{
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
if (jsonRatingProperty.ValueKind == JsonValueKind.Null)
{
errors.Add(new RequiredValueMissingError([.. path, "Rating"]));
}
else if (jsonRatingProperty.ValueKind == JsonValueKind.Number)
{
obj.Rating = jsonRatingProperty.GetInt32();
}
else
{
errors.Add(new ValueHasWrongTypeError([.. path, "Rating"], "Number", jsonRatingProperty.ValueKind.ToString()));
}
}
else
{
errors.Add(new RequiredPropertyMissingError([.. path, "Rating"]));
}
if(errors.Any())
{
return Result<FartingUnicorn.Tests.SingleField.IntType.NonNullableNonOptional_Tests.BlogPost>.Error(errors);
}
if(false)/*check if is option*/
{
}
else
{
return Result<FartingUnicorn.Tests.SingleField.IntType.NonNullableNonOptional_Tests.BlogPost>.Ok(obj);
}
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using DotNetThoughts.Results;
using System.Text.Json;

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)
{
if(path is null)
{
path = ["$"];
}
/*object*/
{
if (jsonElement.ValueKind != JsonValueKind.Object)
{
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
if (jsonRatingProperty.ValueKind == JsonValueKind.Null)
{
obj.Rating = new None<Int32>();
}
else if (jsonRatingProperty.ValueKind == JsonValueKind.Number)
{
obj.Rating = new Some<int>(jsonRatingProperty.GetInt32());
}
else
{
errors.Add(new ValueHasWrongTypeError([.. path, "Rating"], "Number", jsonRatingProperty.ValueKind.ToString()));
}
}
else
{
errors.Add(new RequiredPropertyMissingError([.. path, "Rating"]));
}
if(errors.Any())
{
return Result<FartingUnicorn.Tests.SingleField.IntType.NonNullableOptional_Tests.BlogPost>.Error(errors);
}
if(false)/*check if is option*/
{
}
else
{
return Result<FartingUnicorn.Tests.SingleField.IntType.NonNullableOptional_Tests.BlogPost>.Ok(obj);
}
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using DotNetThoughts.Results;
using System.Text.Json;

namespace FartingUnicorn.Generated;

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

List<IError> errors = new();
var isRatingPropertyDefined = jsonElement.TryGetProperty("Rating", out var jsonRatingProperty);
if (isRatingPropertyDefined)
{
// type = Int32, isOption = False, isNullable = True
if (jsonRatingProperty.ValueKind == JsonValueKind.Null)
{
errors.Add(new RequiredValueMissingError([.. path, "Rating"]));
}
else if (jsonRatingProperty.ValueKind == JsonValueKind.Number)
{
obj.Rating = jsonRatingProperty.GetInt32();
}
else
{
errors.Add(new ValueHasWrongTypeError([.. path, "Rating"], "Number", jsonRatingProperty.ValueKind.ToString()));
}
}
else
{
obj.Rating = null;
}
if(errors.Any())
{
return Result<FartingUnicorn.Tests.SingleField.IntType.NullableNonOptional_Tests.BlogPost>.Error(errors);
}
if(false)/*check if is option*/
{
}
else
{
return Result<FartingUnicorn.Tests.SingleField.IntType.NullableNonOptional_Tests.BlogPost>.Ok(obj);
}
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using DotNetThoughts.Results;
using System.Text.Json;

namespace FartingUnicorn.Generated;

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

List<IError> errors = new();
var isRatingPropertyDefined = jsonElement.TryGetProperty("Rating", out var jsonRatingProperty);
if (isRatingPropertyDefined)
{
// type = Int32, isOption = True, isNullable = True
if (jsonRatingProperty.ValueKind == JsonValueKind.Null)
{
obj.Rating = new None<Int32>();
}
else if (jsonRatingProperty.ValueKind == JsonValueKind.Number)
{
obj.Rating = new Some<int>(jsonRatingProperty.GetInt32());
}
else
{
errors.Add(new ValueHasWrongTypeError([.. path, "Rating"], "Number", jsonRatingProperty.ValueKind.ToString()));
}
}
else
{
obj.Rating = null;
}
if(errors.Any())
{
return Result<FartingUnicorn.Tests.SingleField.IntType.NullableOptional_Tests.BlogPost>.Error(errors);
}
if(false)/*check if is option*/
{
}
else
{
return Result<FartingUnicorn.Tests.SingleField.IntType.NullableOptional_Tests.BlogPost>.Ok(obj);
}
throw new NotImplementedException();
}
}
Loading

0 comments on commit 242de30

Please sign in to comment.