Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
27 changes: 27 additions & 0 deletions samples/Onion/Domain/Age.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Vogen;

namespace Domain;

[ValueObject]
public readonly partial struct Age
{
public static bool operator <(Age left, Age right)
{
return left.CompareTo(right) < 0;
}

public static bool operator <=(Age left, Age right)
{
return left.CompareTo(right) <= 0;
}

public static bool operator >(Age left, Age right)
{
return left.CompareTo(right) > 0;
}

public static bool operator >=(Age left, Age right)
{
return left.CompareTo(right) >= 0;
}
}
27 changes: 27 additions & 0 deletions samples/Onion/Domain/CustomerId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Vogen;

namespace Domain;

[ValueObject]
public partial struct CustomerId
{
public static bool operator <(CustomerId left, CustomerId right)
{
return left.CompareTo(right) < 0;
}

public static bool operator <=(CustomerId left, CustomerId right)
{
return left.CompareTo(right) <= 0;
}

public static bool operator >(CustomerId left, CustomerId right)
{
return left.CompareTo(right) > 0;
}

public static bool operator >=(CustomerId left, CustomerId right)
{
return left.CompareTo(right) >= 0;
}
}
27 changes: 27 additions & 0 deletions samples/Onion/Domain/CustomerName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Vogen;

namespace Domain;

[ValueObject<string>]
public partial struct CustomerName
{
public static bool operator <(CustomerName left, CustomerName right)
{
return left.CompareTo(right) < 0;
}

public static bool operator <=(CustomerName left, CustomerName right)
{
return left.CompareTo(right) <= 0;
}

public static bool operator >(CustomerName left, CustomerName right)
{
return left.CompareTo(right) > 0;
}

public static bool operator >=(CustomerName left, CustomerName right)
{
return left.CompareTo(right) >= 0;
}
}
27 changes: 27 additions & 0 deletions samples/Onion/Domain/Department.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Vogen;

namespace Domain;

[ValueObject<string>]
public readonly partial record struct Department
{
public static bool operator <(Department left, Department right)
{
return left.CompareTo(right) < 0;
}

public static bool operator <=(Department left, Department right)
{
return left.CompareTo(right) <= 0;
}

public static bool operator >(Department left, Department right)
{
return left.CompareTo(right) > 0;
}

public static bool operator >=(Department left, Department right)
{
return left.CompareTo(right) >= 0;
}
}
12 changes: 12 additions & 0 deletions samples/Onion/Domain/EmployeeEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Domain;

public class EmployeeEntity
{
public Id Id { get; set; } = null!; // must be null in order for EF core to generate a value
public required Name Name { get; set; } = Name.NotSet;
public required Age Age { get; set; }

public required Department Department { get; set; }

public required HireDate HireDate { get; set; }
}
27 changes: 27 additions & 0 deletions samples/Onion/Domain/Id.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Vogen;

namespace Domain;

[ValueObject]
public partial class Id
{
public static bool operator <(Id left, Id right)
{
return ReferenceEquals(left, null) ? !ReferenceEquals(right, null) : left.CompareTo(right) < 0;
}

public static bool operator <=(Id left, Id right)
{
return ReferenceEquals(left, null) || left.CompareTo(right) <= 0;
}

public static bool operator >(Id left, Id right)
{
return !ReferenceEquals(left, null) && left.CompareTo(right) > 0;
}

public static bool operator >=(Id left, Id right)
{
return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.CompareTo(right) >= 0;
}
}
63 changes: 22 additions & 41 deletions samples/Onion/Domain/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,26 @@

namespace Domain;

[ValueObject]
public partial struct CustomerId;

[ValueObject<string>]
public partial struct CustomerName;

[ValueObject]
public partial struct OrderId;

public class Order
{
public CustomerId CustomerId { get; set; }
public OrderId OrderId { get; set; }
public CustomerName CustomerName { get; set; }
}

public class EmployeeEntity
{
public Id Id { get; set; } = null!; // must be null in order for EF core to generate a value
public required Name Name { get; set; } = Name.NotSet;
public required Age Age { get; set; }

public required Department Department { get; set; }

public required HireDate HireDate { get; set; }
}

[ValueObject]
public partial class Id;

[ValueObject<string>]
[Instance("NotSet", "[NOT_SET]")]
public partial class Name;

[ValueObject]
public readonly partial struct Age;

[ValueObject<string>]
public readonly partial record struct Department;

[ValueObject<DateOnly>]
public partial record class HireDate;
public partial record class HireDate
{
public static bool operator <(HireDate left, HireDate right)
{
return ReferenceEquals(left, null) ? !ReferenceEquals(right, null) : left.CompareTo(right) < 0;
}

public static bool operator <=(HireDate left, HireDate right)
{
return ReferenceEquals(left, null) || left.CompareTo(right) <= 0;
}

public static bool operator >(HireDate left, HireDate right)
{
return !ReferenceEquals(left, null) && left.CompareTo(right) > 0;
}

public static bool operator >=(HireDate left, HireDate right)
{
return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.CompareTo(right) >= 0;
}
}
28 changes: 28 additions & 0 deletions samples/Onion/Domain/Name.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Vogen;

namespace Domain;

[ValueObject<string>]
[Instance("NotSet", "[NOT_SET]")]
public partial class Name
{
public static bool operator <(Name left, Name right)
{
return ReferenceEquals(left, null) ? !ReferenceEquals(right, null) : left.CompareTo(right) < 0;
}

public static bool operator <=(Name left, Name right)
{
return ReferenceEquals(left, null) || left.CompareTo(right) <= 0;
}

public static bool operator >(Name left, Name right)
{
return !ReferenceEquals(left, null) && left.CompareTo(right) > 0;
}

public static bool operator >=(Name left, Name right)
{
return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.CompareTo(right) >= 0;
}
}
8 changes: 8 additions & 0 deletions samples/Onion/Domain/Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Domain;

public class Order
{
public CustomerId CustomerId { get; set; }
public OrderId OrderId { get; set; }
public CustomerName CustomerName { get; set; }
}
27 changes: 27 additions & 0 deletions samples/Onion/Domain/OrderId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Vogen;

namespace Domain;

[ValueObject]
public partial struct OrderId
{
public static bool operator <(OrderId left, OrderId right)
{
return left.CompareTo(right) < 0;
}

public static bool operator <=(OrderId left, OrderId right)
{
return left.CompareTo(right) <= 0;
}

public static bool operator >(OrderId left, OrderId right)
{
return left.CompareTo(right) > 0;
}

public static bool operator >=(OrderId left, OrderId right)
{
return left.CompareTo(right) >= 0;
}
}
6 changes: 6 additions & 0 deletions samples/WebApplication.Shared/Age.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using Vogen;

namespace WebApplication.Shared;

[ValueObject]
public partial struct Age;
3 changes: 1 addition & 2 deletions samples/WebApplication.Shared/Class1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ namespace WebApplication.Shared;


[ValueObject]
public partial struct SharedStruct;

public partial struct SharedStruct;
6 changes: 6 additions & 0 deletions samples/WebApplication.Shared/Name.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using Vogen;

namespace WebApplication.Shared;

[ValueObject<string>]
public partial class Name;
13 changes: 10 additions & 3 deletions samples/WebApplication/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma warning disable ASPDEPR002
//using Microsoft.OpenApi.Any;

using Microsoft.OpenApi;
using Vogen;
using WebApplication.Shared;

#if USE_SWASHBUCKLE
[assembly: VogenDefaults(openApiSchemaCustomizations: OpenApiSchemaCustomizations.GenerateSwashbuckleMappingExtensionMethod)]
Expand All @@ -14,14 +14,17 @@
#endif



var builder = Microsoft.AspNetCore.Builder.WebApplication.CreateBuilder(args);

#if USE_MICROSOFT_OPENAPI_AND_SCALAR
builder.Services.AddOpenApi((OpenApiOptions o) =>
{
o.MapVogenTypesInOpenApiMarkers();
});
#endif


#if USE_SWASHBUCKLE
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
Expand All @@ -47,7 +50,6 @@
app.UseSwaggerUI();
#endif


app.UseHttpsRedirection();
app.MapControllers();

Expand Down Expand Up @@ -123,4 +125,9 @@
app.MapScalarApiReference();
#endif

app.Run();
app.Run();

[OpenApiMarker<City>]
[OpenApiMarker<Age>]
[OpenApiMarker<Name>]
public partial class OpenApiMarkers;
13 changes: 11 additions & 2 deletions src/Vogen.SharedTypes/EfCoreConverterAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@

namespace Vogen;



[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class EfCoreConverterAttribute<T> : ConversionMarkerAttribute
{
}

/// <summary>
/// Decorated partial classes with these attributes will ensure that Vogen generates an OpenApi schema for the value object specified.
/// Add multiple attributes to generate multiple Open API registrationss.
/// NOTE: Only Open API Version 2.0 and greater is supported.
/// </summary>
/// <typeparam name="T"></typeparam>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class OpenApiMarkerAttribute<T> : ConversionMarkerAttribute
{
}

public class ConversionMarkerAttribute : Attribute
{
}
Loading
Loading