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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions samples/WebApplication/OrdersController.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using Microsoft.AspNetCore.Mvc;
using WebApplication.Shared;

[ApiController]
[Route("api/[controller]")]
public class OrdersController : ControllerBase
{
private static readonly Order[] _orders =
[
new() { OrderId = OrderId.From(1), CustomerName = CustomerName.From("Fred")},
new() { OrderId = OrderId.From(2), CustomerName = CustomerName.From("Barney")}
new() { OrderId = OrderId.From(1), CustomerName = CustomerName.From("Fred"), SharedStruct = SharedStruct.From(1), CustomerCategory = Category.From(1),CustomerCode = Code.From(111), CustomerSecretCode = SecretCode.From('A')},
new() { OrderId = OrderId.From(2), CustomerName = CustomerName.From("Barney"),SharedStruct = SharedStruct.From(2), CustomerCategory = Category.From(2), CustomerCode = Code.From(222), CustomerSecretCode = SecretCode.From('Z')}
];

[HttpGet]
Expand Down
5 changes: 5 additions & 0 deletions samples/WebApplication/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,9 @@
[OpenApiMarker<City>]
[OpenApiMarker<Age>]
[OpenApiMarker<Name>]
[OpenApiMarker<SecretCode>]
[OpenApiMarker<SharedStruct>]
[OpenApiMarker<Code>]
[OpenApiMarker<Category>]
[OpenApiMarker<SecretCode>]
public partial class OpenApiMarkers;
14 changes: 13 additions & 1 deletion samples/WebApplication/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ public partial struct OrderId
{
}

[ValueObject<Guid>]
[ValueObject<byte>]
public partial struct Category;

[ValueObject<short>]
public partial struct Code;

[ValueObject<char>]
public partial struct SecretCode;

[ValueObject<char>]
public readonly partial struct HistoricForecastId;

public class Order
Expand All @@ -39,5 +48,8 @@ public class Order

public SharedStruct SharedStruct { get; init; }
public SharedStruct? SharedStructOrNull { get; init; }
public Category CustomerCategory { get; set; }
public Code CustomerCode { get; set; }
public SecretCode CustomerSecretCode { get; set; }
}

2 changes: 1 addition & 1 deletion samples/WebApplication/WebApplication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseLocallyBuiltPackage>true</UseLocallyBuiltPackage>
<OpenApiMode>MicrosoftAndScalar</OpenApiMode>
<OpenApiMode>Swashbuckle-net8</OpenApiMode>
</PropertyGroup>

<PropertyGroup Condition=" '$(OpenApiMode)' == 'Swashbuckle-net8'">
Expand Down
4 changes: 2 additions & 2 deletions src/Vogen/GenerateCodeForOpenApiSchemaCustomization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ internal static TypeAndFormat MapUnderlyingTypeToJsonSchema(Item workItem)
{
"System.Int32" => new("integer", "Number", "int32"),
"System.Int64" => new("integer", "Number", "int64"),
"System.Int16" => new("number", "Number", ""),
"System.Int16" => new("integer", "Integer", ""),
"System.Single" => new("number", "Number", ""),
"System.Decimal" => new("number", "Number", "double"),
"System.Double" => new("number", "Number", "double"),
Expand All @@ -279,7 +279,7 @@ internal static TypeAndFormat MapUnderlyingTypeToJsonSchema(Item workItem)
"System.DateTime" => new("string", "String", "date-time"),
"System.DateTimeOffset" => new("string", "String", "date-time"),
"System.Guid" => new("string", "String", "uuid"),
"System.Byte" => new("string", "String", "byte"),
"System.Byte" => new("integer", "Integer", ""),
_ => TryMapComplexPrimitive(workItem.IParsableIsAvailable)
};

Expand Down
36 changes: 36 additions & 0 deletions tests/SnapshotTests/BugFixes/Bug896_ByteMappingInOpenApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Threading.Tasks;
using Shared;
using Vogen;

namespace SnapshotTests.BugFixes;

// See https://github.com/SteveDunn/Vogen/issues/575
public class Bug896_ByteMappingInOpenApi
{
[Fact]
public async Task ByteMapping()
{
var source =
$$"""
using System;
using Vogen;

[assembly: VogenDefaults(openApiSchemaCustomizations: OpenApiSchemaCustomizations.GenerateOpenApiMappingExtensionMethod)]

namespace N;

[ValueObject<byte>]
public partial class MyVoByte { }

[ValueObject<char>]
public partial class MyVoChar { }

[ValueObject<char>]
public partial class MyVoShort { }
""";

await new SnapshotRunner<ValueObjectGenerator>()
.WithSource(source)
.RunOn(TargetFramework.Net9_0);
}
}

This file was deleted.

This file was deleted.

Loading
Loading