From 40372c7a98d47b75c34a5ad83837a1a89f87bf56 Mon Sep 17 00:00:00 2001 From: HavenDV Date: Wed, 10 Jul 2024 07:55:55 +0400 Subject: [PATCH] refactor: Added OpenAI.Generators.Core. --- OpenAI.sln | 7 + .../CodeAsOpenApi/Models/ParameterData.cs | 14 -- .../CodeAsOpenApi/SourceGenerationHelper.cs | 56 ----- .../Conversion/ToModels.cs} | 74 ++++--- .../Models/InterfaceData.cs | 0 .../Models/MethodData.cs | 4 +- .../Models/OpenApiSchema.cs} | 8 +- .../OpenAI.Generators.Core.csproj} | 18 +- .../Generators/OpenAiFunctionsGenerator.cs | 204 +----------------- .../OpenAI.Generators/Models/InterfaceData.cs | 6 - .../OpenAI.Generators/Models/MethodData.cs | 8 - .../OpenAI.Generators.csproj | 5 + src/libs/OpenAI.Generators/Sources.Tools.cs | 3 +- src/libs/OpenAI/OpenAI.csproj | 2 + .../CodeAsOpenApi.Tests.csproj | 48 ----- .../CodeAsOpenApi.Tests/SnapshotTests.cs | 29 --- src/tests/CodeAsOpenApi.Tests/TestHelper.cs | 41 ---- .../OpenAI.Generators.IntegrationTests.csproj | 1 + 18 files changed, 79 insertions(+), 449 deletions(-) delete mode 100644 src/libs/CodeAsOpenApi/Models/ParameterData.cs delete mode 100755 src/libs/CodeAsOpenApi/SourceGenerationHelper.cs rename src/libs/{CodeAsOpenApi/OpenAiFunctionsGenerator.cs => OpenAI.Generators.Core/Conversion/ToModels.cs} (80%) mode change 100755 => 100644 rename src/libs/{CodeAsOpenApi => OpenAI.Generators.Core}/Models/InterfaceData.cs (100%) rename src/libs/{CodeAsOpenApi => OpenAI.Generators.Core}/Models/MethodData.cs (70%) rename src/libs/{OpenAI.Generators/Models/ParameterData.cs => OpenAI.Generators.Core/Models/OpenApiSchema.cs} (54%) rename src/libs/{CodeAsOpenApi/CodeAsOpenApi.csproj => OpenAI.Generators.Core/OpenAI.Generators.Core.csproj} (54%) delete mode 100644 src/libs/OpenAI.Generators/Models/InterfaceData.cs delete mode 100644 src/libs/OpenAI.Generators/Models/MethodData.cs delete mode 100644 src/tests/CodeAsOpenApi.Tests/CodeAsOpenApi.Tests.csproj delete mode 100755 src/tests/CodeAsOpenApi.Tests/SnapshotTests.cs delete mode 100755 src/tests/CodeAsOpenApi.Tests/TestHelper.cs diff --git a/OpenAI.sln b/OpenAI.sln index 7806fc94..bc5f7637 100755 --- a/OpenAI.sln +++ b/OpenAI.sln @@ -39,6 +39,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FixOpenApiSpec", "src\helpe EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "helpers", "helpers", "{1A008ECD-2300-4BE4-A302-49DDF8BE0D54}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.Generators.Core", "src\libs\OpenAI.Generators.Core\OpenAI.Generators.Core.csproj", "{FCBE699C-CCD3-4809-8128-78956BC3F2C3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -73,6 +75,10 @@ Global {594DCFD8-E707-4232-B878-90FA3D880474}.Debug|Any CPU.Build.0 = Debug|Any CPU {594DCFD8-E707-4232-B878-90FA3D880474}.Release|Any CPU.ActiveCfg = Release|Any CPU {594DCFD8-E707-4232-B878-90FA3D880474}.Release|Any CPU.Build.0 = Release|Any CPU + {FCBE699C-CCD3-4809-8128-78956BC3F2C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FCBE699C-CCD3-4809-8128-78956BC3F2C3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FCBE699C-CCD3-4809-8128-78956BC3F2C3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FCBE699C-CCD3-4809-8128-78956BC3F2C3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -85,6 +91,7 @@ Global {4F534836-40A3-4E75-8B71-C46CD4FBE137} = {AAA11B78-2764-4520-A97E-46AA7089A588} {74A51E6E-2955-4909-A075-13D8E620FBFE} = {61E7E11E-4558-434C-ACE8-06316A3097B3} {594DCFD8-E707-4232-B878-90FA3D880474} = {1A008ECD-2300-4BE4-A302-49DDF8BE0D54} + {FCBE699C-CCD3-4809-8128-78956BC3F2C3} = {61E7E11E-4558-434C-ACE8-06316A3097B3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {CED9A020-DBA5-4BE6-8096-75E528648EC1} diff --git a/src/libs/CodeAsOpenApi/Models/ParameterData.cs b/src/libs/CodeAsOpenApi/Models/ParameterData.cs deleted file mode 100644 index 76ea60fc..00000000 --- a/src/libs/CodeAsOpenApi/Models/ParameterData.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace H.Generators; - -public readonly record struct ParameterData( - string Name, - string Description, - string Type, - string SchemaType, - string? Format, - IReadOnlyCollection EnumValues, - IReadOnlyCollection Properties, - IReadOnlyCollection ArrayItem, - bool IsRequired, - bool IsNullable, - string DefaultValue); \ No newline at end of file diff --git a/src/libs/CodeAsOpenApi/SourceGenerationHelper.cs b/src/libs/CodeAsOpenApi/SourceGenerationHelper.cs deleted file mode 100755 index 28f6566e..00000000 --- a/src/libs/CodeAsOpenApi/SourceGenerationHelper.cs +++ /dev/null @@ -1,56 +0,0 @@ -namespace H.Generators; - -internal static class SourceGenerationHelper -{ - /// - /// https://swagger.io/docs/specification/data-models/data-types/ - /// - /// - /// - /// - public static string GenerateOpenApiSchema(ParameterData parameter, int depth = 0) - { - var indent = new string(' ', depth * 4); - if (parameter.ArrayItem.Count != 0) - { - return $@"new -{indent} {{ -{indent} type = ""{parameter.SchemaType}"", -{indent} description = ""{parameter.Description}"", -{indent} items = {GenerateOpenApiSchema(parameter.ArrayItem.First(), depth: depth + 1)}, -{indent} }}"; - } - if (parameter.Properties.Count != 0) - { - return $@"new -{indent} {{ -{indent} type = ""{parameter.SchemaType}"", -{indent} description = ""{parameter.Description}"", -{indent} properties = new Dictionary -{indent} {{ -{indent} {string.Join(",\n " + indent, parameter.Properties.Select(x => $@"[""{x.Name}""] = " + GenerateOpenApiSchema(x, depth: depth + 2)))} -{indent} }}, -{indent} required = new string[] {{ {string.Join(", ", parameter.Properties - .Where(static x => x.IsRequired) - .Select(static x => $"\"{x.Name}\""))} }}, -{indent} }}"; - } - - if (parameter.EnumValues.Count != 0) - { - return $@"new -{indent} {{ -{indent} type = ""{parameter.SchemaType}"", -{indent} description = ""{parameter.Description}"", -{indent} @enum = new string[] {{ {string.Join(", ", parameter.EnumValues.Select(static x => $"\"{x}\""))} }}, -{indent} }}"; - } - - return $@"new -{indent} {{ -{indent} type = ""{parameter.SchemaType}"",{(parameter.Format != null ? $@" -{indent} format = ""{parameter.Format}""," : "")} -{indent} description = ""{parameter.Description}"", -{indent} }}"; - } -} diff --git a/src/libs/CodeAsOpenApi/OpenAiFunctionsGenerator.cs b/src/libs/OpenAI.Generators.Core/Conversion/ToModels.cs old mode 100755 new mode 100644 similarity index 80% rename from src/libs/CodeAsOpenApi/OpenAiFunctionsGenerator.cs rename to src/libs/OpenAI.Generators.Core/Conversion/ToModels.cs index a175598f..ac075192 --- a/src/libs/CodeAsOpenApi/OpenAiFunctionsGenerator.cs +++ b/src/libs/OpenAI.Generators.Core/Conversion/ToModels.cs @@ -1,25 +1,16 @@ -using System.ComponentModel; +using System.ComponentModel; +using H.Generators; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp.Syntax; -namespace H.Generators; +namespace OpenAI.Generators.Core.Conversion; -public class OpenAiFunctionsGenerator +public static class ToModels { - #region Methods - - private static string GetDescription(ISymbol symbol) - { - return symbol.GetAttributes() - .FirstOrDefault(static x => x.AttributeClass?.Name == nameof(DescriptionAttribute))? - .ConstructorArguments.First().Value?.ToString() ?? string.Empty; - } - - private static InterfaceData PrepareData( - (SemanticModel SemanticModel, AttributeData AttributeData, InterfaceDeclarationSyntax InterfaceSyntax, INamedTypeSymbol InterfaceSymbol) tuple) + public static InterfaceData PrepareData( + this INamedTypeSymbol interfaceSymbol) { - var (_, _, _, interfaceSymbol) = tuple; - + interfaceSymbol = interfaceSymbol ?? throw new ArgumentNullException(nameof(interfaceSymbol)); + var methods = interfaceSymbol .GetMembers() .OfType() @@ -29,14 +20,26 @@ private static InterfaceData PrepareData( Description: GetDescription(x), IsAsync: x.IsAsync || x.ReturnType.Name == "Task", IsVoid: x.ReturnsVoid, - Parameters: x.Parameters - .Where(static x => x.Type.MetadataName != "CancellationToken") - .Select(static x => ToParameterData( - typeSymbol: x.Type, - name: x.Name, - description: GetDescription(x), - isRequired: !x.IsOptional)) - .ToArray())) + Parameters: new OpenApiSchema( + Name: x.Name, + Description: GetDescription(x), + Type: "object", + SchemaType: "object", + Properties: + x.Parameters + .Where(static x => x.Type.MetadataName != "CancellationToken") + .Select(static x => ToParameterData( + typeSymbol: x.Type, + name: x.Name, + description: GetDescription(x), + isRequired: !x.IsOptional)) + .ToArray(), + EnumValues: Array.Empty(), + IsNullable: false, + IsRequired: true, + Format: null, + ArrayItem: Array.Empty(), + DefaultValue: string.Empty))) .ToArray(); return new InterfaceData( @@ -45,12 +48,12 @@ private static InterfaceData PrepareData( Methods: methods); } - private static ParameterData ToParameterData(ITypeSymbol typeSymbol, string? name = null, string? description = null, bool isRequired = true) + private static OpenApiSchema ToParameterData(ITypeSymbol typeSymbol, string? name = null, string? description = null, bool isRequired = true) { string schemaType; string? format = null; - var properties = Array.Empty(); - ParameterData? arrayItem = null; + var properties = Array.Empty(); + OpenApiSchema? arrayItem = null; switch (typeSymbol.TypeKind) { case TypeKind.Enum: @@ -148,7 +151,7 @@ private static ParameterData ToParameterData(ITypeSymbol typeSymbol, string? nam throw new NotImplementedException($"{typeSymbol.TypeKind} is not implemented."); } - return new ParameterData( + return new OpenApiSchema( Name: !string.IsNullOrWhiteSpace(name) ? name! : typeSymbol.Name, @@ -160,16 +163,14 @@ private static ParameterData ToParameterData(ITypeSymbol typeSymbol, string? nam SchemaType: schemaType, Format: format, Properties: properties, - ArrayItem: arrayItem != null - ? new []{ arrayItem.Value } - : Array.Empty(), + ArrayItem: arrayItem != null ? [arrayItem.Value] : Array.Empty(), EnumValues: typeSymbol.TypeKind == TypeKind.Enum ? typeSymbol .GetMembers() .OfType() .Select(static x => x.Name.ToLowerInvariant()) .ToArray() - : Array.Empty(), + : [], IsNullable: IsNullable(typeSymbol), IsRequired: isRequired); } @@ -204,5 +205,10 @@ private static string GetDefaultValue(ITypeSymbol typeSymbol) } } - #endregion + private static string GetDescription(ISymbol symbol) + { + return symbol.GetAttributes() + .FirstOrDefault(static x => x.AttributeClass?.Name == nameof(DescriptionAttribute))? + .ConstructorArguments.First().Value?.ToString() ?? string.Empty; + } } \ No newline at end of file diff --git a/src/libs/CodeAsOpenApi/Models/InterfaceData.cs b/src/libs/OpenAI.Generators.Core/Models/InterfaceData.cs similarity index 100% rename from src/libs/CodeAsOpenApi/Models/InterfaceData.cs rename to src/libs/OpenAI.Generators.Core/Models/InterfaceData.cs diff --git a/src/libs/CodeAsOpenApi/Models/MethodData.cs b/src/libs/OpenAI.Generators.Core/Models/MethodData.cs similarity index 70% rename from src/libs/CodeAsOpenApi/Models/MethodData.cs rename to src/libs/OpenAI.Generators.Core/Models/MethodData.cs index a6be9651..ae6d71cf 100644 --- a/src/libs/CodeAsOpenApi/Models/MethodData.cs +++ b/src/libs/OpenAI.Generators.Core/Models/MethodData.cs @@ -1,3 +1,5 @@ +using OpenAI.Generators.Core; + namespace H.Generators; public readonly record struct MethodData( @@ -5,4 +7,4 @@ public readonly record struct MethodData( string Description, bool IsAsync, bool IsVoid, - IReadOnlyCollection Parameters); \ No newline at end of file + OpenApiSchema Parameters); \ No newline at end of file diff --git a/src/libs/OpenAI.Generators/Models/ParameterData.cs b/src/libs/OpenAI.Generators.Core/Models/OpenApiSchema.cs similarity index 54% rename from src/libs/OpenAI.Generators/Models/ParameterData.cs rename to src/libs/OpenAI.Generators.Core/Models/OpenApiSchema.cs index 3b7b6240..5e954477 100644 --- a/src/libs/OpenAI.Generators/Models/ParameterData.cs +++ b/src/libs/OpenAI.Generators.Core/Models/OpenApiSchema.cs @@ -1,14 +1,14 @@ -namespace H.Generators; +namespace OpenAI.Generators.Core; -public readonly record struct SchemaData( +public readonly record struct OpenApiSchema( string Name, string Description, string Type, string SchemaType, string? Format, IReadOnlyCollection EnumValues, - IReadOnlyCollection Properties, - IReadOnlyCollection ArrayItem, + IReadOnlyCollection Properties, + IReadOnlyCollection ArrayItem, bool IsRequired, bool IsNullable, string DefaultValue); \ No newline at end of file diff --git a/src/libs/CodeAsOpenApi/CodeAsOpenApi.csproj b/src/libs/OpenAI.Generators.Core/OpenAI.Generators.Core.csproj similarity index 54% rename from src/libs/CodeAsOpenApi/CodeAsOpenApi.csproj rename to src/libs/OpenAI.Generators.Core/OpenAI.Generators.Core.csproj index 911c15a4..8e72f615 100644 --- a/src/libs/CodeAsOpenApi/CodeAsOpenApi.csproj +++ b/src/libs/OpenAI.Generators.Core/OpenAI.Generators.Core.csproj @@ -1,20 +1,26 @@ - + - netstandard2.0 + net4.6.2;netstandard2.0;net6.0;net8.0 false false - true - true - $(NoWarn);CA1014;CA1031;CA1308 + $(NoWarn);CA1308 + + + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive + + + + \ No newline at end of file diff --git a/src/libs/OpenAI.Generators/Generators/OpenAiFunctionsGenerator.cs b/src/libs/OpenAI.Generators/Generators/OpenAiFunctionsGenerator.cs index ec030a33..5a3002ca 100755 --- a/src/libs/OpenAI.Generators/Generators/OpenAiFunctionsGenerator.cs +++ b/src/libs/OpenAI.Generators/Generators/OpenAiFunctionsGenerator.cs @@ -1,7 +1,7 @@ -using System.ComponentModel; -using H.Generators.Extensions; +using H.Generators.Extensions; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; +using OpenAI.Generators.Core.Conversion; namespace H.Generators; @@ -32,211 +32,13 @@ public void Initialize(IncrementalGeneratorInitializationContext context) .SelectAndReportExceptions(AsCalls, context, Id) .AddSource(context); } - - private static string GetDescription(ISymbol symbol) - { - return symbol.GetAttributes() - .FirstOrDefault(static x => x.AttributeClass?.Name == nameof(DescriptionAttribute))? - .ConstructorArguments.First().Value?.ToString() ?? string.Empty; - } private static InterfaceData PrepareData( (SemanticModel SemanticModel, AttributeData AttributeData, InterfaceDeclarationSyntax InterfaceSyntax, INamedTypeSymbol InterfaceSymbol) tuple) { var (_, _, _, interfaceSymbol) = tuple; - var methods = interfaceSymbol - .GetMembers() - .OfType() - .Where(static x => x.MethodKind == MethodKind.Ordinary) - .Select(static x => new MethodData( - Name: x.Name, - Description: GetDescription(x), - IsAsync: x.IsAsync || x.ReturnType.Name == "Task", - IsVoid: x.ReturnsVoid, - Parameters: new SchemaData( - Name: x.Name, - Description: GetDescription(x), - Type: "object", - SchemaType: "object", - Properties: - x.Parameters - .Where(static x => x.Type.MetadataName != "CancellationToken") - .Select(static x => ToParameterData( - typeSymbol: x.Type, - name: x.Name, - description: GetDescription(x), - isRequired: !x.IsOptional)) - .ToArray(), - EnumValues: Array.Empty(), - IsNullable: false, - IsRequired: true, - Format: null, - ArrayItem: Array.Empty(), - DefaultValue: string.Empty))) - .ToArray(); - - return new InterfaceData( - Namespace: interfaceSymbol.ContainingNamespace.ToDisplayString(), - Name: interfaceSymbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat), - Methods: methods); - } - - private static SchemaData ToParameterData(ITypeSymbol typeSymbol, string? name = null, string? description = null, bool isRequired = true) - { - string schemaType; - string? format = null; - var properties = Array.Empty(); - SchemaData? arrayItem = null; - switch (typeSymbol.TypeKind) - { - case TypeKind.Enum: - schemaType = "string"; - break; - - case TypeKind.Structure: - switch (typeSymbol.SpecialType) - { - case SpecialType.System_Int32: - schemaType = "integer"; - format = "int32"; - break; - - case SpecialType.System_Int64: - schemaType = "integer"; - format = "int64"; - break; - - case SpecialType.System_Single: - schemaType = "number"; - format = "double"; - break; - - case SpecialType.System_Double: - schemaType = "number"; - format = "float"; - break; - - case SpecialType.System_DateTime: - schemaType = "string"; - format = "date-time"; - break; - - case SpecialType.System_Boolean: - schemaType = "boolean"; - break; - - case SpecialType.None: - switch (typeSymbol.Name) - { - case "DateOnly": - schemaType = "string"; - format = "date"; - break; - - default: - throw new NotImplementedException($"{typeSymbol.Name} is not implemented."); - } - break; - - default: - throw new NotImplementedException($"{typeSymbol.SpecialType} is not implemented."); - } - break; - - case TypeKind.Class: - switch (typeSymbol.SpecialType) - { - case SpecialType.System_String: - schemaType = "string"; - break; - - - case SpecialType.None: - schemaType = "object"; - properties = typeSymbol.GetMembers() - .OfType() - .Select(static y => ToParameterData( - typeSymbol: y.Type, - name: y.Name, - description: GetDescription(y), - isRequired: true)) - .ToArray(); - break; - - default: - throw new NotImplementedException($"{typeSymbol.SpecialType} is not implemented."); - } - break; - - case TypeKind.Interface when typeSymbol.MetadataName == "IReadOnlyCollection`1": - schemaType = "array"; - arrayItem = (typeSymbol as INamedTypeSymbol)?.TypeArguments - .Select(static y => ToParameterData(y)) - .FirstOrDefault(); - break; - - case TypeKind.Array: - schemaType = "array"; - arrayItem = ToParameterData((typeSymbol as IArrayTypeSymbol)?.ElementType!); - break; - - default: - throw new NotImplementedException($"{typeSymbol.TypeKind} is not implemented."); - } - - return new SchemaData( - Name: !string.IsNullOrWhiteSpace(name) - ? name! - : typeSymbol.Name, - Description: !string.IsNullOrWhiteSpace(description) - ? description! - : GetDescription(typeSymbol), - Type: typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), - DefaultValue: GetDefaultValue(typeSymbol), - SchemaType: schemaType, - Format: format, - Properties: properties, - ArrayItem: arrayItem != null ? [arrayItem.Value] : Array.Empty(), - EnumValues: typeSymbol.TypeKind == TypeKind.Enum - ? typeSymbol - .GetMembers() - .OfType() - .Select(static x => x.Name.ToLowerInvariant()) - .ToArray() - : Array.Empty(), - IsNullable: IsNullable(typeSymbol), - IsRequired: isRequired); - } - - private static bool IsNullable(ITypeSymbol typeSymbol) - { - if (typeSymbol.TypeKind == TypeKind.Enum) - { - return false; - } - if (typeSymbol.TypeKind == TypeKind.Structure) - { - return false; - } - - return typeSymbol.SpecialType switch - { - SpecialType.System_String => false, - _ => true, - }; - } - - private static string GetDefaultValue(ITypeSymbol typeSymbol) - { - switch (typeSymbol.SpecialType) - { - case SpecialType.System_String: - return "string.Empty"; - - default: - return string.Empty; - } + return interfaceSymbol.PrepareData(); } private static FileWithName AsTools(InterfaceData @interface) diff --git a/src/libs/OpenAI.Generators/Models/InterfaceData.cs b/src/libs/OpenAI.Generators/Models/InterfaceData.cs deleted file mode 100644 index 2f78ed9d..00000000 --- a/src/libs/OpenAI.Generators/Models/InterfaceData.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace H.Generators; - -public readonly record struct InterfaceData( - string Namespace, - string Name, - IReadOnlyCollection Methods); \ No newline at end of file diff --git a/src/libs/OpenAI.Generators/Models/MethodData.cs b/src/libs/OpenAI.Generators/Models/MethodData.cs deleted file mode 100644 index 35b1ac9b..00000000 --- a/src/libs/OpenAI.Generators/Models/MethodData.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace H.Generators; - -public readonly record struct MethodData( - string Name, - string Description, - bool IsAsync, - bool IsVoid, - SchemaData Parameters); \ No newline at end of file diff --git a/src/libs/OpenAI.Generators/OpenAI.Generators.csproj b/src/libs/OpenAI.Generators/OpenAI.Generators.csproj index cdd89109..b0cadef9 100644 --- a/src/libs/OpenAI.Generators/OpenAI.Generators.csproj +++ b/src/libs/OpenAI.Generators/OpenAI.Generators.csproj @@ -18,4 +18,9 @@ + + + + \ No newline at end of file diff --git a/src/libs/OpenAI.Generators/Sources.Tools.cs b/src/libs/OpenAI.Generators/Sources.Tools.cs index 0619d27f..69c66134 100755 --- a/src/libs/OpenAI.Generators/Sources.Tools.cs +++ b/src/libs/OpenAI.Generators/Sources.Tools.cs @@ -1,4 +1,5 @@ using H.Generators.Extensions; +using OpenAI.Generators.Core; namespace H.Generators; @@ -11,7 +12,7 @@ internal static partial class Sources /// /// /// - public static string GenerateOpenApiSchema(SchemaData parameter, int depth = 0, bool schema = true) + public static string GenerateOpenApiSchema(OpenApiSchema parameter, int depth = 0, bool schema = true) { var indent = new string(' ', depth * 4); var name = schema ? "global::OpenAI.OpenApiSchema" : "global::OpenAI.FunctionParameters"; diff --git a/src/libs/OpenAI/OpenAI.csproj b/src/libs/OpenAI/OpenAI.csproj index dea03ef9..95fabc40 100644 --- a/src/libs/OpenAI/OpenAI.csproj +++ b/src/libs/OpenAI/OpenAI.csproj @@ -41,6 +41,8 @@ + + diff --git a/src/tests/CodeAsOpenApi.Tests/CodeAsOpenApi.Tests.csproj b/src/tests/CodeAsOpenApi.Tests/CodeAsOpenApi.Tests.csproj deleted file mode 100644 index 6f7e55fb..00000000 --- a/src/tests/CodeAsOpenApi.Tests/CodeAsOpenApi.Tests.csproj +++ /dev/null @@ -1,48 +0,0 @@ - - - - net8.0 - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/tests/CodeAsOpenApi.Tests/SnapshotTests.cs b/src/tests/CodeAsOpenApi.Tests/SnapshotTests.cs deleted file mode 100755 index 959d98ee..00000000 --- a/src/tests/CodeAsOpenApi.Tests/SnapshotTests.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace H.Generators.IntegrationTests; - -[TestClass] -public class IpcGeneratorSnapshotTests : VerifyBase -{ - // [TestMethod] - // public Task GeneratesCorrectly() - // { - // return this.CheckSourceAsync(Resources.WeatherFunctions_cs.AsString()); - // } - // - // [TestMethod] - // public Task GeneratesUpdateCodeCorrectly() - // { - // return this.CheckSourceAsync(Resources.UpdateCodeFunctions_cs.AsString()); - // } - // - // [TestMethod] - // public Task VariousTypes() - // { - // return this.CheckSourceAsync(Resources.VariousTypesFunctions_cs.AsString()); - // } - // - // [TestMethod] - // public Task MaintenanceFunctionsTypes() - // { - // return this.CheckSourceAsync(Resources.MaintenanceFunctions_cs.AsString()); - // } -} \ No newline at end of file diff --git a/src/tests/CodeAsOpenApi.Tests/TestHelper.cs b/src/tests/CodeAsOpenApi.Tests/TestHelper.cs deleted file mode 100755 index 9efe2d1e..00000000 --- a/src/tests/CodeAsOpenApi.Tests/TestHelper.cs +++ /dev/null @@ -1,41 +0,0 @@ -// using Microsoft.CodeAnalysis; -// using Microsoft.CodeAnalysis.CSharp; -// using Microsoft.CodeAnalysis.Testing; -// -// namespace H.Generators.IntegrationTests; -// -// public static class TestHelper -// { -// public static async Task CheckSourceAsync( -// this VerifyBase verifier, -// string source, -// CancellationToken cancellationToken = default) -// { -// var referenceAssemblies = ReferenceAssemblies.Net.Net60; -// var references = await referenceAssemblies.ResolveAsync(null, cancellationToken); -// references = references -// .Add(MetadataReference.CreateFromFile(typeof(tryAGI.OpenAI.OpenAiFunctionsAttribute).Assembly.Location)); -// -// var compilation = (Compilation)CSharpCompilation.Create( -// assemblyName: "Tests", -// syntaxTrees: new[] -// { -// CSharpSyntaxTree.ParseText(source, cancellationToken: cancellationToken), -// }, -// references: references, -// options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); -// var driver = CSharpGeneratorDriver -// .Create(new OpenAiFunctionsGenerator()) -// .RunGeneratorsAndUpdateCompilation(compilation, out compilation, out _, cancellationToken); -// var diagnostics = compilation.GetDiagnostics(cancellationToken); -// -// await Task.WhenAll( -// verifier -// .Verify(diagnostics) -// .UseDirectory("Snapshots") -// .UseTextForParameters("Diagnostics"), -// verifier -// .Verify(driver) -// .UseDirectory("Snapshots")); -// } -// } \ No newline at end of file diff --git a/src/tests/OpenAI.Generators.IntegrationTests/OpenAI.Generators.IntegrationTests.csproj b/src/tests/OpenAI.Generators.IntegrationTests/OpenAI.Generators.IntegrationTests.csproj index 95917204..c2791e2c 100644 --- a/src/tests/OpenAI.Generators.IntegrationTests/OpenAI.Generators.IntegrationTests.csproj +++ b/src/tests/OpenAI.Generators.IntegrationTests/OpenAI.Generators.IntegrationTests.csproj @@ -23,6 +23,7 @@ +