Skip to content

Commit

Permalink
Make a base class override a final decision.
Browse files Browse the repository at this point in the history
  • Loading branch information
Corniel committed Nov 21, 2024
1 parent 159eb3c commit dc41765
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
10 changes: 2 additions & 8 deletions src/Qowaiv.CodeGeneration.OpenApi/ClassExtender.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Qowaiv.CodeGeneration.OpenApi.Collections;
using Qowaiv.CodeGeneration.Syntax;
using Qowaiv.Diagnostics.Contracts;

Expand All @@ -9,18 +8,13 @@ public static class ClassExtender
{
/// <summary>Overrides the All-of collection to a single base that the class has to obey.</summary>
[FluentSyntax]
public static Class WithBase(this Class @class, Type? @base, ResolveOpenApiSchema schema)
public static Class WithBase(this Class @class, Type @base, ResolveOpenApiSchema schema)
{
Guard.NotNull(@base);
Guard.NotNull(schema);

var data = schema.Context.GetEntry(schema)!.Data!;

((TypeCollector)data.AllOfs!).Clear();
if (@base is { })
{
data.AddAllOfs([@base]);
}
data.Manual.BaseType = @base;

return @class;
}
Expand Down
8 changes: 7 additions & 1 deletion src/Qowaiv.CodeGeneration.OpenApi/OpenApiTypeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Qowaiv.CodeGeneration.OpenApi;
internal sealed record OpenApiTypeData : TypeData
{
private readonly OpenApiResolveContext Context;
internal readonly Manuals Manual = new();

/// <summary>Initializes a new instance of the <see cref="OpenApiTypeData"/> class.</summary>
public OpenApiTypeData(OpenApiResolveContext context)
Expand All @@ -21,7 +22,7 @@ public OpenApiTypeData(OpenApiResolveContext context)
/// <inheritdoc />
public override Type? BaseType
{
get => GetBaseType();
get => Manual.BaseType ?? GetBaseType();
init => throw new NotSupportedException();
}

Expand Down Expand Up @@ -81,4 +82,9 @@ internal void AddAttributes(IEnumerable<AttributeInfo> attributes)
private bool DifferentTypeName(Type type)
=> type is not TypeBase tp
|| tp.TypeName != TypeName;

internal sealed class Manuals
{
public Type? BaseType { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>0.0.1-alpha-027</Version>
<Version>0.0.1-alpha-028</Version>
<PackageId>Qowaiv.CodeGeneration.OpenApi</PackageId>
<PackageReleaseNotes>
<![CDATA[
Expand Down
2 changes: 1 addition & 1 deletion src/Qowaiv.CodeGeneration/Qowaiv.CodeGeneration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>0.0.1-alpha-027</Version>
<Version>0.0.1-alpha-028</Version>
<PackageId>Qowaiv.CodeGeneration</PackageId>
<PackageReleaseNotes>
<![CDATA[
Expand Down

0 comments on commit dc41765

Please sign in to comment.