SteveDunn / Vogen

A semi-opinionated library which is a source generator and a code analyser. It Source generates Value Objects
Apache License 2.0
887 stars 46 forks source link

Vogen 4.0.5 Issues #604

Closed Aragas closed 5 months ago

Aragas commented 6 months ago

Hey Steve! Just started to use the new version, here's some issues discovered!

1. OpenAPI

When using OpenApiSchemaCustomizations.GenerateSwashbuckleMappingExtensionMethod The VogenSwashbuckleExtensions class is referencing the Vogen types without specifying a namespace

global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType<TenantId>(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "object" });

Instead of providing a full namespace

global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType<global::BUTR.Site.NexusMods.Server.Models.TenantId>(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "object" });

2. IVogen<,>

IVogen<TType, TValueType> is not assigned to the Vogen type in the autogenerated code, you need to manually assign it to the Vogen type like this

[ValueObject<string>]
public readonly partial struct TenantId : IVogen<TenantId, string>
Aragas commented 6 months ago

3. DevelopmentDependency

The DevelopmentDependency flag will not work the way Vogen is currently setup. Vogen requires to ship Vogen.SharedTypes, but the behaviour for DevelopmentDependency is to exclude the compile part - the compiler will not be able to see those shared types. Not sure if there's something else going on, except this

SteveDunn commented 5 months ago

Oops! Thanks for spotting @Aragas - I'm doing a build now for the nuget issue. I'll take a look at the others later. The nuget issue should be fixed in 4.0.6

SteveDunn commented 5 months ago

Re.

IVogen<TType, TValueType> is not assigned to the Vogen type in the autogenerated code, you need to manually assign it to the Vogen type like this

This is controlled by the StaticAbstractsGeneration flag in global config. It is also only generated for projects using C# 11. What are you targetting?

Aragas commented 5 months ago

Re.

IVogen<TType, TValueType> is not assigned to the Vogen type in the autogenerated code, you need to manually assign it to the Vogen type like this

This is controlled by the StaticAbstractsGeneration flag in global config. It is also only generated for projects using C# 11. What are you targetting?

.NET 8. Looks like it doesn't work if you do not explicitly specify the <LangVersion> tag, even if it's already implied it's past 11 with .NET 8. Once I added <LangVersion>12</LangVersion> it started to work

SteveDunn commented 5 months ago

That's odd. I thought the behaviour of this was to default to latest. I'll investigate that. I plan on adding an analyzer that spots usage on unsupported langversions.

SteveDunn commented 5 months ago

Do you have a global.json file? I'm just wondering why it's not 11 or more. When I run a .NET 8 app with no langversion, it default to preview (presumably because it's being build with the .NET 9 SDK)

SteveDunn commented 5 months ago

I'll release another version shortly that outputs a diganostics.cs file.

Could you add this to your project and tell me what it says?

namespace Vogen;

public class __ProduceDiagnostics { }

The contents should look something like:

/*

LanguageVersion: Preview

User provided global config
===========
UnderlyingType: null
ValidationExceptionType: null
Conversions: Default
Customizations: None
DeserializationStrictness: Default
DebuggerAttributes: Default
Comparison: Default
StringComparers: Unspecified
ParsableForStrings: GenerateMethodsAndInterface
ParsableForPrimitives: HoistMethodsAndInterfaces
ToPrimitiveCasting: Explicit
FromPrimitiveCasting: Explicit
DisableStackTraceRecordingInDebug: False
TryFromGeneration: Unspecified
IsInitializedMethodGeneration: Unspecified
SystemTextJsonConverterFactoryGeneration: Unspecified
OpenApiSchemaCustomizations: GenerateSwashbuckleMappingExtensionMethod
StaticAbstractsGeneration: Unspecified

Resolved global config
===========
UnderlyingType: null
ValidationExceptionType: null
Conversions: Default
Customizations: None
DeserializationStrictness: Default
DebuggerAttributes: Full
Comparison: UseUnderlying
StringComparers: Omit
ParsableForStrings: GenerateMethodsAndInterface
ParsableForPrimitives: HoistMethodsAndInterfaces
ToPrimitiveCasting: Explicit
FromPrimitiveCasting: Explicit
DisableStackTraceRecordingInDebug: False
TryFromGeneration: GenerateBoolAndErrorOrMethods
IsInitializedMethodGeneration: Generate
SystemTextJsonConverterFactoryGeneration: Generate
OpenApiSchemaCustomizations: GenerateSwashbuckleMappingExtensionMethod
StaticAbstractsGeneration: Omit

Targets
===========
ForecastDate
City
Farenheit
Centigrade
CustomerName
OrderId

*/
Aragas commented 5 months ago

@SteveDunn just to be sure, I assume there should have been a version 4.0.7 for that, right?

SteveDunn commented 5 months ago

@SteveDunn just to be sure, I assume there should have been a version 4.0.7 for that, right?

@Aragas - it'll be in 4.0.6, which I'm just building now

SteveDunn commented 5 months ago

@Aragas - sorry, yes, 4.0.7. On it's way to NuGet now! Thanks for the reports. Let me know if there's any issues.

Aragas commented 5 months ago

Just to confirm, the diagnostics works. Also, without LangVersion property it does see now that it's 11 and adds the IVogen interface!

SteveDunn commented 5 months ago

Excellent - great news - thanks for checking!