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
4 changes: 2 additions & 2 deletions .github/Skills/domainprimitive-builder/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ Validation must be pure.

# Validation Logic Rules

Validation defines domain invariants and must be explicit and domain-focused.
Validation defines domain invariants and must be explicit and domain-focused. Validation method must not call Transform.

## Preferred Error Return Style

Expand Down Expand Up @@ -354,7 +354,7 @@ Templates must follow Structural Generator Safety Rules.

## Transform (Normalization) Rules

Optional normalization hook executed before Validate.
Optional normalization hook executed before Validate.

Signature:

Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Product>Domain Primitives</Product>
<Company>ALTA Software llc.</Company>
<Copyright>Copyright © 2024 ALTA Software llc.</Copyright>
<Version>7.1.1</Version>
<Version>8.0.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
19 changes: 4 additions & 15 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<ItemGroup>
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.*" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.*" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="10.0.*" />
<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerGen" Version="10.1.*" />
<PackageVersion Include="Microsoft.OpenApi" Version="2.6.*" />

<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.*" />
<PackageVersion Include="Verify.SourceGenerators" Version="2.5.*" />
<PackageVersion Include="Verify.Xunit" Version="31.9.3" />
Expand All @@ -16,19 +20,4 @@
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerGen" Version="9.0.*" />
<PackageVersion Include="Microsoft.OpenApi" Version="1.6.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerGen" Version="9.0.*" />
<PackageVersion Include="Microsoft.OpenApi" Version="1.6.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="10.0.*" />
<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerGen" Version="10.1.*" />
<PackageVersion Include="Microsoft.OpenApi" Version="2.6.*" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,10 @@

<ItemGroup>
<PackageReference Include="Scalar.AspNetCore" Version="2.12.5" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.12" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<ProjectReference Include="..\..\src\AltaSoft.DomainPrimitives.OpenApiExtensions\AltaSoft.DomainPrimitives.OpenApiExtensions.csproj" />
</ItemGroup>
Expand Down
7 changes: 2 additions & 5 deletions Examples/DomainPrimitivesDemo/DomainPrimitivesDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
</PropertyGroup>


<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.OpenApi" Version="1.6.28" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<PackageReference Include="Microsoft.OpenApi" Version="2.4.2" />
<ItemGroup>
<PackageReference Include="Microsoft.OpenApi" Version="2.6.1" />
</ItemGroup>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using AltaSoft.DomainPrimitives.Generator.Extensions;
using AltaSoft.DomainPrimitives.Generator.Models;
using Microsoft.CodeAnalysis;
Expand All @@ -27,14 +26,8 @@ internal static void AddOpenApiSchemas(string assemblyName, List<GeneratorData>
var builder = new SourceCodeBuilder();
builder.AppendSourceHeader("AltaSoft DomainPrimitives Generator");

builder.AppendLine("#if NET10_0_OR_GREATER", false)
.AppendLine("using Microsoft.OpenApi;", false)
.AppendLine("#else", false)
.AppendLine("using Microsoft.OpenApi.Models;", false)
.AppendLine("using Microsoft.OpenApi.Any;", false)
.AppendLine("#endif");

var usings = types.ConvertAll(x => x.Namespace);
usings.Add("Microsoft.OpenApi");
usings.Add("System");
usings.Add("System.Collections.Frozen");
usings.Add("System.Collections.Generic");
Expand Down Expand Up @@ -65,7 +58,6 @@ internal static void AddOpenApiSchemas(string assemblyName, List<GeneratorData>
}
builder.AppendLine("/// </remarks>");

builder.NewLine().AppendLine("#if NET10_0_OR_GREATER", false);
builder.AppendLine("public static FrozenDictionary<Type, OpenApiSchema> Schemas = new Dictionary<Type, OpenApiSchema>()")
.OpenBracket();

Expand Down Expand Up @@ -129,90 +121,8 @@ void AddMapping()
builder.Rollback(builder.GetNewLineLength() + 1).NewLine();
builder.CloseBracketWithString(".ToFrozenDictionary();");

builder.NewLine();
builder.AppendLine("#else", false);

builder.AppendLine("public static FrozenDictionary<Type, OpenApiSchema> Schemas = new Dictionary<Type, OpenApiSchema>()")
.OpenBracket();

ProcessOldVersionOpenApi(types, builder, context.CancellationToken);

builder.Rollback(builder.GetNewLineLength() + 1).NewLine();
builder.CloseBracketWithString(".ToFrozenDictionary();");
builder.AppendLine("#endif", false);

builder.CloseBracket();
context.AddSource("OpenApiHelper.g.cs", builder.ToString());

return;

static void ProcessOldVersionOpenApi(List<GeneratorData> types, SourceCodeBuilder builder, CancellationToken cancellationToken)
{
foreach (var data in types)
{
var (typeName, format) = data.PrimitiveTypeSymbol.GetOldOpenApiTypeAndFormat();

// Get the XML documentation comment for the namedTypeSymbol
var xmlDocumentation = data.TypeSymbol.GetDocumentationCommentXml(cancellationToken: cancellationToken);

AddOldMapping(false);

if (data.TypeSymbol.IsValueType)
{
builder.NewLine();
AddOldMapping(true);
}

continue;

void AddOldMapping(bool isNullable)
{
builder.OpenBracket();

builder.Append("typeof(").Append(data.ClassName).AppendIf(isNullable, "?").AppendLine("),");

builder.Append("new OpenApiSchema")
.OpenBracket()
.Append("Type = ").Append(Quote(typeName)).AppendLine(",");

if (!string.IsNullOrEmpty(format))
builder.Append("Format = ").Append(QuoteAndEscape(data.SerializationFormat ?? format)).AppendLine(",");

if (isNullable)
builder.AppendLine("Nullable = true,");

var title = isNullable ? $"Nullable<{data.ClassName}>" : data.ClassName;

builder.Append("Title = ").Append(Quote(title)).AppendLine(",");

if (!string.IsNullOrEmpty(xmlDocumentation))
{
var xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml(xmlDocumentation);

// Select the <summary> node
var summaryNode = xmlDoc.SelectSingleNode("member/summary");

if (summaryNode is not null)
{
builder.Append("Description = @").Append(Quote(summaryNode.InnerText.Trim())).AppendLine(",");
}

var example = xmlDoc.SelectSingleNode("member/example");
if (example is not null)
{
var exampleValue = example.InnerText.Trim().Replace("\"", "\\\"");
builder.Append("Example = new OpenApiString(").Append("\"" + exampleValue + "\"").AppendLine("),");
}
}

builder.Length -= SourceCodeBuilder.s_newLineLength + 1;
builder.NewLine();
builder.AppendLine("}");
builder.CloseBracketWithComma();
}
}
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
#if NET10_0_OR_GREATER
using Microsoft.OpenApi;
#else
using Microsoft.OpenApi.Models;
#endif

namespace AltaSoft.DomainPrimitives.OpenApiExtensions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
using System.Runtime.CompilerServices;
using AltaSoft.DomainPrimitives.OpenApiExtensions;
using Microsoft.Extensions.DependencyInjection;
#if NET10_0_OR_GREATER
using Microsoft.OpenApi;
#else
using Microsoft.OpenApi.Models;
#endif
using Swashbuckle.AspNetCore.SwaggerGen;

// ReSharper disable UnusedMember.Global
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@

#nullable enable

#if NET10_0_OR_GREATER
using Microsoft.OpenApi;
#else
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Any;
#endif
using AltaSoft.DomainPrimitives;
using Microsoft.OpenApi;
using System;
using System.Collections.Frozen;
using System.Collections.Generic;
Expand All @@ -37,8 +32,6 @@ public static class OpenApiHelper
/// <see cref="BoolValue" />
/// </para>
/// </remarks>

#if NET10_0_OR_GREATER
public static FrozenDictionary<Type, OpenApiSchema> Schemas = new Dictionary<Type, OpenApiSchema>()
{
{
Expand All @@ -50,28 +43,4 @@ public static class OpenApiHelper
}
}
}.ToFrozenDictionary();

#else
public static FrozenDictionary<Type, OpenApiSchema> Schemas = new Dictionary<Type, OpenApiSchema>()
{
{
typeof(BoolValue),
new OpenApiSchema
{
Type = "boolean",
Title = "BoolValue"
}
},

{
typeof(BoolValue?),
new OpenApiSchema
{
Type = "boolean",
Nullable = true,
Title = "Nullable<BoolValue>"
}
}
}.ToFrozenDictionary();
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@

#nullable enable

#if NET10_0_OR_GREATER
using Microsoft.OpenApi;
#else
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Any;
#endif
using AltaSoft.DomainPrimitives;
using Microsoft.OpenApi;
using System;
using System.Collections.Frozen;
using System.Collections.Generic;
Expand All @@ -37,8 +32,6 @@ public static class OpenApiHelper
/// <see cref="ByteValue" />
/// </para>
/// </remarks>

#if NET10_0_OR_GREATER
public static FrozenDictionary<Type, OpenApiSchema> Schemas = new Dictionary<Type, OpenApiSchema>()
{
{
Expand All @@ -51,30 +44,4 @@ public static class OpenApiHelper
}
}
}.ToFrozenDictionary();

#else
public static FrozenDictionary<Type, OpenApiSchema> Schemas = new Dictionary<Type, OpenApiSchema>()
{
{
typeof(ByteValue),
new OpenApiSchema
{
Type = "integer",
Format = "byte",
Title = "ByteValue"
}
},

{
typeof(ByteValue?),
new OpenApiSchema
{
Type = "integer",
Format = "byte",
Nullable = true,
Title = "Nullable<ByteValue>"
}
}
}.ToFrozenDictionary();
#endif
}
Loading