Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasnordqvist committed Nov 11, 2024
1 parent b64953c commit 0a7a1b3
Show file tree
Hide file tree
Showing 5 changed files with 531 additions and 143 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using DotNetThoughts.Results;
using System.Text.Json;
using static FartingUnicorn.MapperOptions;

namespace FartingUnicorn.Generated;

public static partial class Mappers
{
public static Result<FartingUnicorn.Tests.MultipleFields.WithOptions.PATCH.BlogPost> MapToFartingUnicorn_Tests_MultipleFields_WithOptions_PATCH_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.MultipleFields.WithOptions.PATCH.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
var obj = new FartingUnicorn.Tests.MultipleFields.WithOptions.PATCH.BlogPost();

List<IError> errors = new();
var isCategoryPropertyDefined = jsonElement.TryGetProperty("Category", out var jsonCategoryProperty);
if (isCategoryPropertyDefined)
{
// type = System.String, isOption = True, isNullable = True
if (jsonCategoryProperty.ValueKind == JsonValueKind.Null)
{
obj.Category = new None<System.String>();
}
else if (jsonCategoryProperty.ValueKind == JsonValueKind.String)
{
obj.Category = new Some<string>(jsonCategoryProperty.GetString());
}
else
{
errors.Add(new ValueHasWrongTypeError([.. path, "Category"], "String", jsonCategoryProperty.ValueKind.ToString()));
}
}
else
{
obj.Category = null;
}
var isRatingPropertyDefined = jsonElement.TryGetProperty("Rating", out var jsonRatingProperty);
if (isRatingPropertyDefined)
{
// type = System.Int32, isOption = True, isNullable = True
if (jsonRatingProperty.ValueKind == JsonValueKind.Null)
{
obj.Rating = new None<System.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.MultipleFields.WithOptions.PATCH.BlogPost>.Error(errors);
}
if(false)/*check if is option*/
{
}
else
{
return Result<FartingUnicorn.Tests.MultipleFields.WithOptions.PATCH.BlogPost>.Ok(obj);
}
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using DotNetThoughts.Results;
using System.Text.Json;
using static FartingUnicorn.MapperOptions;

namespace FartingUnicorn.Generated;

public static partial class Mappers
{
public static Result<FartingUnicorn.Tests.MultipleFields.WithOptions.PUT.BlogPost> MapToFartingUnicorn_Tests_MultipleFields_WithOptions_PUT_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.MultipleFields.WithOptions.PUT.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
var obj = new FartingUnicorn.Tests.MultipleFields.WithOptions.PUT.BlogPost();

List<IError> errors = new();
var isCategoryPropertyDefined = jsonElement.TryGetProperty("Category", out var jsonCategoryProperty);
if (isCategoryPropertyDefined)
{
// type = System.String, isOption = True, isNullable = False
if (jsonCategoryProperty.ValueKind == JsonValueKind.Null)
{
obj.Category = new None<System.String>();
}
else if (jsonCategoryProperty.ValueKind == JsonValueKind.String)
{
obj.Category = new Some<string>(jsonCategoryProperty.GetString());
}
else
{
errors.Add(new ValueHasWrongTypeError([.. path, "Category"], "String", jsonCategoryProperty.ValueKind.ToString()));
}
}
else
{
errors.Add(new RequiredPropertyMissingError([.. path, "Category"]));
}
var isRatingPropertyDefined = jsonElement.TryGetProperty("Rating", out var jsonRatingProperty);
if (isRatingPropertyDefined)
{
// type = System.Int32, isOption = True, isNullable = False
if (jsonRatingProperty.ValueKind == JsonValueKind.Null)
{
obj.Rating = new None<System.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.MultipleFields.WithOptions.PUT.BlogPost>.Error(errors);
}
if(false)/*check if is option*/
{
}
else
{
return Result<FartingUnicorn.Tests.MultipleFields.WithOptions.PUT.BlogPost>.Ok(obj);
}
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using DotNetThoughts.Results;
using System.Text.Json;
using static FartingUnicorn.MapperOptions;

namespace FartingUnicorn.Generated;

public static partial class Mappers
{
public static Result<FartingUnicorn.Tests.MultipleFields.WithoutOptions.PATCH.BlogPost> MapToFartingUnicorn_Tests_MultipleFields_WithoutOptions_PATCH_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.MultipleFields.WithoutOptions.PATCH.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
var obj = new FartingUnicorn.Tests.MultipleFields.WithoutOptions.PATCH.BlogPost();

List<IError> errors = new();
var isTitlePropertyDefined = jsonElement.TryGetProperty("Title", out var jsonTitleProperty);
if (isTitlePropertyDefined)
{
// type = System.String, isOption = False, isNullable = True
if (jsonTitleProperty.ValueKind == JsonValueKind.Null)
{
errors.Add(new RequiredValueMissingError([.. path, "Title"]));
}
else if (jsonTitleProperty.ValueKind == JsonValueKind.String)
{
obj.Title = jsonTitleProperty.GetString();
}
else
{
errors.Add(new ValueHasWrongTypeError([.. path, "Title"], "String", jsonTitleProperty.ValueKind.ToString()));
}
}
else
{
obj.Title = null;
}
var isIsDraftPropertyDefined = jsonElement.TryGetProperty("IsDraft", out var jsonIsDraftProperty);
if (isIsDraftPropertyDefined)
{
// type = System.Boolean, isOption = False, isNullable = True
if (jsonIsDraftProperty.ValueKind == JsonValueKind.Null)
{
errors.Add(new RequiredValueMissingError([.. path, "IsDraft"]));
}
else if (jsonIsDraftProperty.ValueKind == JsonValueKind.True || jsonIsDraftProperty.ValueKind == JsonValueKind.False)
{
obj.IsDraft = jsonIsDraftProperty.GetBoolean();
}
else
{
errors.Add(new ValueHasWrongTypeError([.. path, "IsDraft"], "Boolean", jsonIsDraftProperty.ValueKind.ToString()));
}
}
else
{
obj.IsDraft = null;
}
if(errors.Any())
{
return Result<FartingUnicorn.Tests.MultipleFields.WithoutOptions.PATCH.BlogPost>.Error(errors);
}
if(false)/*check if is option*/
{
}
else
{
return Result<FartingUnicorn.Tests.MultipleFields.WithoutOptions.PATCH.BlogPost>.Ok(obj);
}
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using DotNetThoughts.Results;
using System.Text.Json;
using static FartingUnicorn.MapperOptions;

namespace FartingUnicorn.Generated;

public static partial class Mappers
{
public static Result<FartingUnicorn.Tests.MultipleFields.WithoutOptions.PUT.BlogPost> MapToFartingUnicorn_Tests_MultipleFields_WithoutOptions_PUT_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.MultipleFields.WithoutOptions.PUT.BlogPost>.Error(new ValueHasWrongTypeError(path, "Object", jsonElement.ValueKind.ToString()));
}
var obj = new FartingUnicorn.Tests.MultipleFields.WithoutOptions.PUT.BlogPost();

List<IError> errors = new();
var isTitlePropertyDefined = jsonElement.TryGetProperty("Title", out var jsonTitleProperty);
if (isTitlePropertyDefined)
{
// type = System.String, isOption = False, isNullable = False
if (jsonTitleProperty.ValueKind == JsonValueKind.Null)
{
errors.Add(new RequiredValueMissingError([.. path, "Title"]));
}
else if (jsonTitleProperty.ValueKind == JsonValueKind.String)
{
obj.Title = jsonTitleProperty.GetString();
}
else
{
errors.Add(new ValueHasWrongTypeError([.. path, "Title"], "String", jsonTitleProperty.ValueKind.ToString()));
}
}
else
{
errors.Add(new RequiredPropertyMissingError([.. path, "Title"]));
}
var isIsDraftPropertyDefined = jsonElement.TryGetProperty("IsDraft", out var jsonIsDraftProperty);
if (isIsDraftPropertyDefined)
{
// type = System.Boolean, isOption = False, isNullable = False
if (jsonIsDraftProperty.ValueKind == JsonValueKind.Null)
{
errors.Add(new RequiredValueMissingError([.. path, "IsDraft"]));
}
else if (jsonIsDraftProperty.ValueKind == JsonValueKind.True || jsonIsDraftProperty.ValueKind == JsonValueKind.False)
{
obj.IsDraft = jsonIsDraftProperty.GetBoolean();
}
else
{
errors.Add(new ValueHasWrongTypeError([.. path, "IsDraft"], "Boolean", jsonIsDraftProperty.ValueKind.ToString()));
}
}
else
{
errors.Add(new RequiredPropertyMissingError([.. path, "IsDraft"]));
}
if(errors.Any())
{
return Result<FartingUnicorn.Tests.MultipleFields.WithoutOptions.PUT.BlogPost>.Error(errors);
}
if(false)/*check if is option*/
{
}
else
{
return Result<FartingUnicorn.Tests.MultipleFields.WithoutOptions.PUT.BlogPost>.Ok(obj);
}
throw new NotImplementedException();
}
}
Loading

0 comments on commit 0a7a1b3

Please sign in to comment.