Skip to content

Commit

Permalink
Fix two small bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Corniel committed Jul 12, 2024
1 parent aeb751b commit 5547655
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ static bool IsNone(EnumerationField field)
[Pure]
private Type? ResolveNumber(ResolveOpenApiSchema schema) => NormalizeFormat(schema.Format) switch
{
"DOUBLE" => typeof(double),
"INT16" => typeof(short),
"INT32" => typeof(int),
"INT64" => typeof(long),
Expand Down
7 changes: 5 additions & 2 deletions src/Qowaiv.CodeGeneration.OpenApi/OpenApiTypeResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public partial class OpenApiTypeResolver(
private readonly OpenApiTypeResolverSettings Settings = settings ?? new OpenApiTypeResolverSettings();

/// <remarks>
/// Types that are null-able by design will not be transformed to
/// Types that are null-able by design will not be transformed to
/// <see cref="Nullable{T}"/>'s when optional.
/// </remarks>
[Pure]
Expand All @@ -27,7 +27,10 @@ protected virtual bool IsNullableByDesign(Type type)
private static bool HasNoneOrEmptyField(Type type)
=> Array.Exists(
array: type.GetFields(BindingFlags.Static | BindingFlags.Public),
match: f => f.FieldType == type && (f.Name == "Empty" || f.Name == "None"));
match: f => f.FieldType == type && (f.Name == "Empty" || f.Name == "None"))
|| Array.Exists(
array: type.GetProperties(BindingFlags.Static | BindingFlags.Public),
match: p => p.PropertyType == type && (p.Name == "Empty" || p.Name == "None"));

[Pure]
protected virtual EnumerationField ResolveEnumField(OpenApiString @enum, Enumeration type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class OpenApiTypeResolverSettings
/// <summary>Property required type (default is <see cref="RequiredTypes.IsRequired"/>).</summary>
public RequiredTypes RequiredType { get; init; } = RequiredTypes.IsRequired;

/// <summary>Indicates that all properties that hare value types should be nullable (default is false).</summary>
/// <summary>Indicates that all properties that are value types should be nullable (default is false).</summary>
/// <remarks>
/// Value types like <see cref="Guid"/> and <see cref="EmailAddress"/> that
/// nullable by design are excluded from this setting.
Expand Down
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-015</Version>
<Version>0.0.1-alpha-016</Version>
<PackageId>Qowaiv.CodeGeneration.OpenApi</PackageId>
<PackageReleaseNotes>
ToBeReleased
Expand Down
4 changes: 3 additions & 1 deletion src/Qowaiv.CodeGeneration/CSharpWriter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Qowaiv.CodeGeneration.Syntax;
using Qowaiv.Reflection;
using System.IO;

namespace Qowaiv.CodeGeneration;
Expand Down Expand Up @@ -83,7 +84,8 @@ public CSharpWriter Write(IEnumerable<Action<CSharpWriter>> writes, Action<CShar
public CSharpWriter Write(Type type, bool attribute)
{
Guard.NotNull(type);
var name = type.ToCSharpString(withNamespace: !Settings.GlobalUsings.Contains(type.Namespace!));
var withoutNamespace = Settings.GlobalUsings.Contains(QowaivType.GetNotNullableType(type).Namespace!);
var name = type.ToCSharpString(!withoutNamespace);
return attribute && name.EndsWith("Attribute")
? Write(name[..^9])
: Write(name);
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-015</Version>
<Version>0.0.1-alpha-016</Version>
<PackageId>Qowaiv.CodeGeneration</PackageId>
<PackageReleaseNotes>
ToBeReleased
Expand Down

0 comments on commit 5547655

Please sign in to comment.