From 095bf0a0e0affe85f8951642b9b60552f103da91 Mon Sep 17 00:00:00 2001 From: Konstantin S Date: Tue, 3 Dec 2024 05:09:13 +0400 Subject: [PATCH] fix: Fixed Discriminator property name for some cases. --- .../AutoSDK/Extensions/OpenApiExtensions.cs | 17 +- src/libs/AutoSDK/Models/AnyOfData.cs | 4 +- src/libs/AutoSDK/Models/MethodParameter.cs | 3 +- src/libs/AutoSDK/Models/PropertyData.cs | 80 +------- src/libs/AutoSDK/Models/SchemaContext.cs | 1 + .../Naming/Clients/ClientNameGenerator.cs | 3 +- .../Naming/Models/ModelNameGenerator.cs | 3 +- .../Properties/PropertyNameGenerator.cs | 105 +++++++++++ ...ests.SdkGenerator_Diagnostics.received.txt | 52 ----- .../_#G.Models.Request.g.verified.cs | 6 +- ...ests.SdkGenerator_Diagnostics.received.txt | 177 ------------------ ...ests.SdkGenerator_Diagnostics.verified.txt | 2 +- .../_#G.Models.Request.g.verified.cs | 6 +- .../_#JsonConverters.Request.g.verified.cs | 6 +- 14 files changed, 130 insertions(+), 335 deletions(-) create mode 100644 src/libs/AutoSDK/Naming/Properties/PropertyNameGenerator.cs delete mode 100644 src/tests/AutoSDK.SnapshotTests/Snapshots/luma/NewtonsoftJson/Tests.SdkGenerator_Diagnostics.received.txt delete mode 100644 src/tests/AutoSDK.SnapshotTests/Snapshots/luma/SystemTextJson/Tests.SdkGenerator_Diagnostics.received.txt diff --git a/src/libs/AutoSDK/Extensions/OpenApiExtensions.cs b/src/libs/AutoSDK/Extensions/OpenApiExtensions.cs index cdccc04273..bbaee5938c 100644 --- a/src/libs/AutoSDK/Extensions/OpenApiExtensions.cs +++ b/src/libs/AutoSDK/Extensions/OpenApiExtensions.cs @@ -8,6 +8,7 @@ using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Readers; using AutoSDK.Models; +using AutoSDK.Naming.Properties; using AutoSDK.Serialization.Form; using Microsoft.OpenApi.Validations; @@ -571,20 +572,6 @@ public static string ClearForXml(this string text) }; } - internal static string ToCSharpName(this string text, Settings settings, SchemaContext? parent) - { - var name = text.ToPropertyName(); - - name = PropertyData.HandleWordSeparators(name); - - if (parent != null) - { - name = name.FixPropertyName(parent.Id); - } - - return PropertyData.SanitizeName(name, settings.ClsCompliantEnumPrefix, true); - } - public static T ResolveIfRequired(this T referenceable) where T : class, IOpenApiReferenceable { referenceable = referenceable ?? throw new ArgumentNullException(nameof(referenceable)); @@ -693,7 +680,7 @@ public static PropertyData ToEnumValue( return PropertyData.Default with { Id = id, - Name = PropertyData.SanitizeName(name, settings.ClsCompliantEnumPrefix), + Name = CSharpPropertyNameGenerator.SanitizeName(name, settings.ClsCompliantEnumPrefix), Summary = ClearForXml(ExtractEnumSummaryFromDescription(id, description)), }; } diff --git a/src/libs/AutoSDK/Models/AnyOfData.cs b/src/libs/AutoSDK/Models/AnyOfData.cs index 8045139563..4a633f3e16 100644 --- a/src/libs/AutoSDK/Models/AnyOfData.cs +++ b/src/libs/AutoSDK/Models/AnyOfData.cs @@ -1,6 +1,7 @@ using System.Collections.Immutable; using AutoSDK.Extensions; using AutoSDK.Naming.AnyOfs; +using AutoSDK.Naming.Properties; using AutoSDK.Serialization.Json; namespace AutoSDK.Models; @@ -39,7 +40,8 @@ public static AnyOfData FromSchemaContext(SchemaContext context) context.Schema.Discriminator.Mapping.Count != 0) { discriminatorType = context.Children.FirstOrDefault(x => x.Hint == Hint.Discriminator)?.TypeData; - discriminatorPropertyName = context.Schema.Discriminator.PropertyName.ToPropertyName(); + discriminatorPropertyName = context.Schema.Discriminator.PropertyName.ToPropertyName() + .ToCSharpName(context.Settings, context.Parent); } var count = context.IsAnyOf diff --git a/src/libs/AutoSDK/Models/MethodParameter.cs b/src/libs/AutoSDK/Models/MethodParameter.cs index 5bda46b595..cb054570c8 100644 --- a/src/libs/AutoSDK/Models/MethodParameter.cs +++ b/src/libs/AutoSDK/Models/MethodParameter.cs @@ -1,6 +1,7 @@ using System.Collections.Immutable; using Microsoft.OpenApi.Models; using AutoSDK.Extensions; +using AutoSDK.Naming.Properties; using AutoSDK.Serialization.Json; namespace AutoSDK.Models; @@ -66,7 +67,7 @@ public static MethodParameter FromSchemaContext(SchemaContext context) name = name.FixPropertyName(context.Parent.Id); } - name = PropertyData.SanitizeName(name, context.Settings.ClsCompliantEnumPrefix, true); + name = CSharpPropertyNameGenerator.SanitizeName(name, context.Settings.ClsCompliantEnumPrefix, true); var isRequired = parameter.Required || diff --git a/src/libs/AutoSDK/Models/PropertyData.cs b/src/libs/AutoSDK/Models/PropertyData.cs index 880cc0a854..7b06d97dd4 100644 --- a/src/libs/AutoSDK/Models/PropertyData.cs +++ b/src/libs/AutoSDK/Models/PropertyData.cs @@ -1,4 +1,5 @@ using AutoSDK.Extensions; +using AutoSDK.Naming.Properties; namespace AutoSDK.Models; @@ -37,7 +38,6 @@ public readonly record struct PropertyData( public static PropertyData FromSchemaContext(SchemaContext context) { context = context ?? throw new ArgumentNullException(nameof(context)); - var propertyName = context.PropertyName ?? throw new InvalidOperationException("Property name or parameter name is required."); var type = context.TypeData; // OpenAPI doesn't allow metadata for references so sometimes allOf with single item is used to add metadata. @@ -50,21 +50,11 @@ public static PropertyData FromSchemaContext(SchemaContext context) }; } - var name = propertyName.ToPropertyName(); - - name = HandleWordSeparators(name); - - if (context.Parent != null) - { - name = name.FixPropertyName(context.Parent.Id); - } - - name = SanitizeName(name, context.Settings.ClsCompliantEnumPrefix, true); - var requiredProperties = context.Parent != null ? new HashSet(context.Parent.Schema.Required) : []; + var propertyName = context.PropertyName ?? throw new InvalidOperationException("Property name or parameter name is required."); var isRequired = requiredProperties.Contains(propertyName) && context.Schema is { WriteOnly: false }; @@ -76,7 +66,7 @@ public static PropertyData FromSchemaContext(SchemaContext context) return new PropertyData( Id: propertyName, - Name: name, + Name: CSharpPropertyNameGenerator.ComputePropertyName(context), Type: type with { CSharpTypeNullability = type.CSharpTypeNullability || context.Schema is { WriteOnly: true }, @@ -99,70 +89,6 @@ public static PropertyData FromSchemaContext(SchemaContext context) DiscriminatorValue: string.Empty); } - internal static string SanitizeName(string? name, string clsCompliantEnumPrefix, bool skipHandlingWordSeparators = false) - { - static bool InvalidFirstChar(char ch) - => ch is not ('_' or >= 'A' and <= 'Z' or >= 'a' and <= 'z'); - - static bool InvalidSubsequentChar(char ch) - => ch is not ( - '_' - or >= 'A' and <= 'Z' - or >= 'a' and <= 'z' - or >= '0' and <= '9' - ); - - if (name is null || name.Length == 0) - { - return ""; - } - - if (!skipHandlingWordSeparators) - { - name = HandleWordSeparators(name); - } - - if (name.Length == 0) - { - return string.IsNullOrWhiteSpace(clsCompliantEnumPrefix) - ? "_" - : clsCompliantEnumPrefix; - } - - if (InvalidFirstChar(name[0])) - { - name = (string.IsNullOrWhiteSpace(clsCompliantEnumPrefix) - ? "_" - : clsCompliantEnumPrefix) + name; - } - - if (!name.Skip(1).Any(InvalidSubsequentChar)) - { - return name; - } - - Span buf = stackalloc char[name.Length]; - name.AsSpan().CopyTo(buf); - - for (var i = 1; i < buf.Length; i++) - { - if (InvalidSubsequentChar(buf[i])) - { - buf[i] = '_'; - } - } - - // Span.ToString implementation checks for char type, new string(&buf[0], buf.length) - return buf.ToString(); - } - - internal static string HandleWordSeparators(string name) - { - return name - .ReplacePlusAndMinusOnStart() - .UseWordSeparator('_', '+', '-', '.', '/', '(', '[', ']', ')'); - } - public string ParameterName => Name .Replace(".", string.Empty) .ToParameterName() diff --git a/src/libs/AutoSDK/Models/SchemaContext.cs b/src/libs/AutoSDK/Models/SchemaContext.cs index e901c447af..748cbe6cc2 100644 --- a/src/libs/AutoSDK/Models/SchemaContext.cs +++ b/src/libs/AutoSDK/Models/SchemaContext.cs @@ -1,6 +1,7 @@ using Microsoft.OpenApi.Models; using AutoSDK.Extensions; using AutoSDK.Naming.Models; +using AutoSDK.Naming.Properties; using Microsoft.OpenApi.Any; namespace AutoSDK.Models; diff --git a/src/libs/AutoSDK/Naming/Clients/ClientNameGenerator.cs b/src/libs/AutoSDK/Naming/Clients/ClientNameGenerator.cs index 031206134f..617c2ad9ec 100644 --- a/src/libs/AutoSDK/Naming/Clients/ClientNameGenerator.cs +++ b/src/libs/AutoSDK/Naming/Clients/ClientNameGenerator.cs @@ -1,6 +1,7 @@ using Microsoft.OpenApi.Models; using AutoSDK.Extensions; using AutoSDK.Models; +using AutoSDK.Naming.Properties; namespace AutoSDK.Naming.Clients; @@ -25,6 +26,6 @@ public static string GeneratePropertyName( .SkipWhile(c => !char.IsDigit(c) && !char.IsLetter(c)) .ToArray()); - return PropertyData.SanitizeName(name.ToClassName(), settings.ClsCompliantEnumPrefix); + return CSharpPropertyNameGenerator.SanitizeName(name.ToClassName(), settings.ClsCompliantEnumPrefix); } } \ No newline at end of file diff --git a/src/libs/AutoSDK/Naming/Models/ModelNameGenerator.cs b/src/libs/AutoSDK/Naming/Models/ModelNameGenerator.cs index fbe5859ae3..496c95b4ce 100644 --- a/src/libs/AutoSDK/Naming/Models/ModelNameGenerator.cs +++ b/src/libs/AutoSDK/Naming/Models/ModelNameGenerator.cs @@ -1,6 +1,7 @@ using Microsoft.OpenApi.Models; using AutoSDK.Extensions; using AutoSDK.Models; +using AutoSDK.Naming.Properties; namespace AutoSDK.Naming.Models; @@ -112,7 +113,7 @@ public static string ComputeId(SchemaContext context) { context = context ?? throw new ArgumentNullException(nameof(context)); - context.ClassName = PropertyData.SanitizeName(context.ComputeClassName(), context.Settings.ClsCompliantEnumPrefix); + context.ClassName = CSharpPropertyNameGenerator.SanitizeName(context.ComputeClassName(), context.Settings.ClsCompliantEnumPrefix); context.Id = context.ClassName; return context.Id; diff --git a/src/libs/AutoSDK/Naming/Properties/PropertyNameGenerator.cs b/src/libs/AutoSDK/Naming/Properties/PropertyNameGenerator.cs new file mode 100644 index 0000000000..a36007a806 --- /dev/null +++ b/src/libs/AutoSDK/Naming/Properties/PropertyNameGenerator.cs @@ -0,0 +1,105 @@ +using AutoSDK.Extensions; +using AutoSDK.Models; + +namespace AutoSDK.Naming.Properties; + +public static class CSharpPropertyNameGenerator +{ + public static string ComputePropertyName( + SchemaContext context) + { + context = context ?? throw new ArgumentNullException(nameof(context)); + var propertyName = context.PropertyName ?? throw new InvalidOperationException("Property name or parameter name is required."); + + var name = propertyName.ToPropertyName(); + + name = HandleWordSeparators(name); + + if (context.Parent != null) + { + name = name.FixPropertyName(context.Parent.Id); + } + + name = SanitizeName(name, context.Settings.ClsCompliantEnumPrefix, true); + + return name; + } + + internal static string SanitizeName(string? name, string clsCompliantEnumPrefix, bool skipHandlingWordSeparators = false) + { + static bool InvalidFirstChar(char ch) + => ch is not ('_' or >= 'A' and <= 'Z' or >= 'a' and <= 'z'); + + static bool InvalidSubsequentChar(char ch) + => ch is not ( + '_' + or >= 'A' and <= 'Z' + or >= 'a' and <= 'z' + or >= '0' and <= '9' + ); + + if (name is null || name.Length == 0) + { + return ""; + } + + if (!skipHandlingWordSeparators) + { + name = HandleWordSeparators(name); + } + + if (name.Length == 0) + { + return string.IsNullOrWhiteSpace(clsCompliantEnumPrefix) + ? "_" + : clsCompliantEnumPrefix; + } + + if (InvalidFirstChar(name[0])) + { + name = (string.IsNullOrWhiteSpace(clsCompliantEnumPrefix) + ? "_" + : clsCompliantEnumPrefix) + name; + } + + if (!name.Skip(1).Any(InvalidSubsequentChar)) + { + return name; + } + + Span buf = stackalloc char[name.Length]; + name.AsSpan().CopyTo(buf); + + for (var i = 1; i < buf.Length; i++) + { + if (InvalidSubsequentChar(buf[i])) + { + buf[i] = '_'; + } + } + + // Span.ToString implementation checks for char type, new string(&buf[0], buf.length) + return buf.ToString(); + } + + internal static string HandleWordSeparators(string name) + { + return name + .ReplacePlusAndMinusOnStart() + .UseWordSeparator('_', '+', '-', '.', '/', '(', '[', ']', ')'); + } + + internal static string ToCSharpName(this string text, Settings settings, SchemaContext? parent) + { + var name = text.ToPropertyName(); + + name = HandleWordSeparators(name); + + if (parent != null) + { + name = name.FixPropertyName(parent.Id); + } + + return SanitizeName(name, settings.ClsCompliantEnumPrefix, true); + } +} \ No newline at end of file diff --git a/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/NewtonsoftJson/Tests.SdkGenerator_Diagnostics.received.txt b/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/NewtonsoftJson/Tests.SdkGenerator_Diagnostics.received.txt deleted file mode 100644 index 12d0b26dbe..0000000000 --- a/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/NewtonsoftJson/Tests.SdkGenerator_Diagnostics.received.txt +++ /dev/null @@ -1,52 +0,0 @@ -[ - { - Location: /* - /// - public global::G.GenerationRequestDiscriminatorGeneration_type? Generation_type { get; } - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -*/ - AutoSDK.SourceGenerators\AutoSDK.SourceGenerators.SdkGenerator\G.Models.Request.g.cs: (14,25)-(14,70), - Message: The type or namespace name 'GenerationRequestDiscriminatorGeneration_type' does not exist in the namespace 'G' (are you missing an assembly reference?), - Severity: Error, - Descriptor: { - Id: CS0234, - Title: , - HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS0234), - MessageFormat: The type or namespace name '{0}' does not exist in the namespace '{1}' (are you missing an assembly reference?), - Category: Compiler, - DefaultSeverity: Error, - IsEnabledByDefault: true, - CustomTags: [ - Compiler, - Telemetry, - NotConfigurable - ] - } - }, - { - Location: /* - public Request( - global::G.GenerationRequestDiscriminatorGeneration_type? generation_type, - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - global::G.GenerationRequest? video, -*/ - AutoSDK.SourceGenerators\AutoSDK.SourceGenerators.SdkGenerator\G.Models.Request.g.cs: (90,22)-(90,67), - Message: The type or namespace name 'GenerationRequestDiscriminatorGeneration_type' does not exist in the namespace 'G' (are you missing an assembly reference?), - Severity: Error, - Descriptor: { - Id: CS0234, - Title: , - HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS0234), - MessageFormat: The type or namespace name '{0}' does not exist in the namespace '{1}' (are you missing an assembly reference?), - Category: Compiler, - DefaultSeverity: Error, - IsEnabledByDefault: true, - CustomTags: [ - Compiler, - Telemetry, - NotConfigurable - ] - } - } -] \ No newline at end of file diff --git a/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/NewtonsoftJson/_#G.Models.Request.g.verified.cs b/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/NewtonsoftJson/_#G.Models.Request.g.verified.cs index 1cd98eddc7..77ff4d7aa8 100644 --- a/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/NewtonsoftJson/_#G.Models.Request.g.verified.cs +++ b/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/NewtonsoftJson/_#G.Models.Request.g.verified.cs @@ -13,7 +13,7 @@ namespace G /// /// /// - public global::G.GenerationRequestDiscriminatorGeneration_type? Generation_type { get; } + public global::G.GenerationRequestDiscriminatorGenerationType? GenerationType { get; } /// /// The generation request object @@ -89,12 +89,12 @@ public Request(global::G.ImageGenerationRequest? value) /// /// public Request( - global::G.GenerationRequestDiscriminatorGeneration_type? generation_type, + global::G.GenerationRequestDiscriminatorGenerationType? generationType, global::G.GenerationRequest? video, global::G.ImageGenerationRequest? image ) { - Generation_type = generation_type; + GenerationType = generationType; Video = video; Image = image; diff --git a/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/SystemTextJson/Tests.SdkGenerator_Diagnostics.received.txt b/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/SystemTextJson/Tests.SdkGenerator_Diagnostics.received.txt deleted file mode 100644 index 475871655b..0000000000 --- a/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/SystemTextJson/Tests.SdkGenerator_Diagnostics.received.txt +++ /dev/null @@ -1,177 +0,0 @@ -[ - { - Location: /* - /// - public global::G.GenerationRequestDiscriminatorGeneration_type? Generation_type { get; } - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -*/ - AutoSDK.SourceGenerators\AutoSDK.SourceGenerators.SdkGenerator\G.Models.Request.g.cs: (14,25)-(14,70), - Message: The type or namespace name 'GenerationRequestDiscriminatorGeneration_type' does not exist in the namespace 'G' (are you missing an assembly reference?), - Severity: Error, - Descriptor: { - Id: CS0234, - Title: , - HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS0234), - MessageFormat: The type or namespace name '{0}' does not exist in the namespace '{1}' (are you missing an assembly reference?), - Category: Compiler, - DefaultSeverity: Error, - IsEnabledByDefault: true, - CustomTags: [ - Compiler, - Telemetry, - NotConfigurable - ] - } - }, - { - Location: /* - public Request( - global::G.GenerationRequestDiscriminatorGeneration_type? generation_type, - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - global::G.GenerationRequest? video, -*/ - AutoSDK.SourceGenerators\AutoSDK.SourceGenerators.SdkGenerator\G.Models.Request.g.cs: (90,22)-(90,67), - Message: The type or namespace name 'GenerationRequestDiscriminatorGeneration_type' does not exist in the namespace 'G' (are you missing an assembly reference?), - Severity: Error, - Descriptor: { - Id: CS0234, - Title: , - HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS0234), - MessageFormat: The type or namespace name '{0}' does not exist in the namespace '{1}' (are you missing an assembly reference?), - Category: Compiler, - DefaultSeverity: Error, - IsEnabledByDefault: true, - CustomTags: [ - Compiler, - Telemetry, - NotConfigurable - ] - } - }, - { - Location: /* - global::G.GenerationRequest? video = default; - if (discriminator?.Generation_type == global::G.GenerationRequestDiscriminatorGeneration_type.Video) - ^^^^^^^^^^^^^^^^ - { -*/ - AutoSDK.SourceGenerators\AutoSDK.SourceGenerators.SdkGenerator\JsonConverters.Request.g.cs: (24,30)-(24,46), - Message: 'GenerationRequestDiscriminator' does not contain a definition for 'Generation_type' and no accessible extension method 'Generation_type' accepting a first argument of type 'GenerationRequestDiscriminator' could be found (are you missing a using directive or an assembly reference?), - Severity: Error, - Descriptor: { - Id: CS1061, - Title: , - HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS1061), - MessageFormat: '{0}' does not contain a definition for '{1}' and no accessible extension method '{1}' accepting a first argument of type '{0}' could be found (are you missing a using directive or an assembly reference?), - Category: Compiler, - DefaultSeverity: Error, - IsEnabledByDefault: true, - CustomTags: [ - Compiler, - Telemetry, - NotConfigurable - ] - } - }, - { - Location: /* - global::G.GenerationRequest? video = default; - if (discriminator?.Generation_type == global::G.GenerationRequestDiscriminatorGeneration_type.Video) - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - { -*/ - AutoSDK.SourceGenerators\AutoSDK.SourceGenerators.SdkGenerator\JsonConverters.Request.g.cs: (24,50)-(24,105), - Message: The type or namespace name 'GenerationRequestDiscriminatorGeneration_type' does not exist in the namespace 'G' (are you missing an assembly reference?), - Severity: Error, - Descriptor: { - Id: CS0234, - Title: , - HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS0234), - MessageFormat: The type or namespace name '{0}' does not exist in the namespace '{1}' (are you missing an assembly reference?), - Category: Compiler, - DefaultSeverity: Error, - IsEnabledByDefault: true, - CustomTags: [ - Compiler, - Telemetry, - NotConfigurable - ] - } - }, - { - Location: /* - global::G.ImageGenerationRequest? image = default; - if (discriminator?.Generation_type == global::G.GenerationRequestDiscriminatorGeneration_type.Image) - ^^^^^^^^^^^^^^^^ - { -*/ - AutoSDK.SourceGenerators\AutoSDK.SourceGenerators.SdkGenerator\JsonConverters.Request.g.cs: (31,30)-(31,46), - Message: 'GenerationRequestDiscriminator' does not contain a definition for 'Generation_type' and no accessible extension method 'Generation_type' accepting a first argument of type 'GenerationRequestDiscriminator' could be found (are you missing a using directive or an assembly reference?), - Severity: Error, - Descriptor: { - Id: CS1061, - Title: , - HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS1061), - MessageFormat: '{0}' does not contain a definition for '{1}' and no accessible extension method '{1}' accepting a first argument of type '{0}' could be found (are you missing a using directive or an assembly reference?), - Category: Compiler, - DefaultSeverity: Error, - IsEnabledByDefault: true, - CustomTags: [ - Compiler, - Telemetry, - NotConfigurable - ] - } - }, - { - Location: /* - global::G.ImageGenerationRequest? image = default; - if (discriminator?.Generation_type == global::G.GenerationRequestDiscriminatorGeneration_type.Image) - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - { -*/ - AutoSDK.SourceGenerators\AutoSDK.SourceGenerators.SdkGenerator\JsonConverters.Request.g.cs: (31,50)-(31,105), - Message: The type or namespace name 'GenerationRequestDiscriminatorGeneration_type' does not exist in the namespace 'G' (are you missing an assembly reference?), - Severity: Error, - Descriptor: { - Id: CS0234, - Title: , - HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS0234), - MessageFormat: The type or namespace name '{0}' does not exist in the namespace '{1}' (are you missing an assembly reference?), - Category: Compiler, - DefaultSeverity: Error, - IsEnabledByDefault: true, - CustomTags: [ - Compiler, - Telemetry, - NotConfigurable - ] - } - }, - { - Location: /* - var result = new global::G.Request( - discriminator?.Generation_type, - ^^^^^^^^^^^^^^^^ - video, -*/ - AutoSDK.SourceGenerators\AutoSDK.SourceGenerators.SdkGenerator\JsonConverters.Request.g.cs: (39,30)-(39,46), - Message: 'GenerationRequestDiscriminator' does not contain a definition for 'Generation_type' and no accessible extension method 'Generation_type' accepting a first argument of type 'GenerationRequestDiscriminator' could be found (are you missing a using directive or an assembly reference?), - Severity: Error, - Descriptor: { - Id: CS1061, - Title: , - HelpLink: https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS1061), - MessageFormat: '{0}' does not contain a definition for '{1}' and no accessible extension method '{1}' accepting a first argument of type '{0}' could be found (are you missing a using directive or an assembly reference?), - Category: Compiler, - DefaultSeverity: Error, - IsEnabledByDefault: true, - CustomTags: [ - Compiler, - Telemetry, - NotConfigurable - ] - } - } -] \ No newline at end of file diff --git a/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/SystemTextJson/Tests.SdkGenerator_Diagnostics.verified.txt b/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/SystemTextJson/Tests.SdkGenerator_Diagnostics.verified.txt index 5f282702bb..ad47dbb93f 100644 --- a/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/SystemTextJson/Tests.SdkGenerator_Diagnostics.verified.txt +++ b/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/SystemTextJson/Tests.SdkGenerator_Diagnostics.verified.txt @@ -1 +1 @@ - \ No newline at end of file +[] \ No newline at end of file diff --git a/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/SystemTextJson/_#G.Models.Request.g.verified.cs b/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/SystemTextJson/_#G.Models.Request.g.verified.cs index 1cd98eddc7..77ff4d7aa8 100644 --- a/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/SystemTextJson/_#G.Models.Request.g.verified.cs +++ b/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/SystemTextJson/_#G.Models.Request.g.verified.cs @@ -13,7 +13,7 @@ namespace G /// /// /// - public global::G.GenerationRequestDiscriminatorGeneration_type? Generation_type { get; } + public global::G.GenerationRequestDiscriminatorGenerationType? GenerationType { get; } /// /// The generation request object @@ -89,12 +89,12 @@ public Request(global::G.ImageGenerationRequest? value) /// /// public Request( - global::G.GenerationRequestDiscriminatorGeneration_type? generation_type, + global::G.GenerationRequestDiscriminatorGenerationType? generationType, global::G.GenerationRequest? video, global::G.ImageGenerationRequest? image ) { - Generation_type = generation_type; + GenerationType = generationType; Video = video; Image = image; diff --git a/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/SystemTextJson/_#JsonConverters.Request.g.verified.cs b/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/SystemTextJson/_#JsonConverters.Request.g.verified.cs index 331f824fc1..e2aeb145d2 100644 --- a/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/SystemTextJson/_#JsonConverters.Request.g.verified.cs +++ b/src/tests/AutoSDK.SnapshotTests/Snapshots/luma/SystemTextJson/_#JsonConverters.Request.g.verified.cs @@ -23,14 +23,14 @@ public class RequestJsonConverter : global::System.Text.Json.Serialization.JsonC var discriminator = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, discriminatorTypeInfo); global::G.GenerationRequest? video = default; - if (discriminator?.Generation_type == global::G.GenerationRequestDiscriminatorGeneration_type.Video) + if (discriminator?.GenerationType == global::G.GenerationRequestDiscriminatorGenerationType.Video) { var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::G.GenerationRequest), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo ?? throw new global::System.InvalidOperationException($"Cannot get type info for {nameof(global::G.GenerationRequest)}"); video = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, typeInfo); } global::G.ImageGenerationRequest? image = default; - if (discriminator?.Generation_type == global::G.GenerationRequestDiscriminatorGeneration_type.Image) + if (discriminator?.GenerationType == global::G.GenerationRequestDiscriminatorGenerationType.Image) { var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::G.ImageGenerationRequest), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo ?? throw new global::System.InvalidOperationException($"Cannot get type info for {nameof(global::G.ImageGenerationRequest)}"); @@ -38,7 +38,7 @@ public class RequestJsonConverter : global::System.Text.Json.Serialization.JsonC } var result = new global::G.Request( - discriminator?.Generation_type, + discriminator?.GenerationType, video, image );