From b6a88cc200afa451a5a51e1a23f472c8bd15efba Mon Sep 17 00:00:00 2001 From: HavenDV Date: Fri, 4 Oct 2024 01:58:56 +0400 Subject: [PATCH] feat(cli): Use OpenApi31Support in init command. --- ...lpers_FixOpenApiSpec_FixOpenApiSpec.csproj | 1 + .../src_helpers_FixOpenApiSpec_Program.cs | 21 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libs/AutoSDK.CLI/Resources/src_helpers_FixOpenApiSpec_FixOpenApiSpec.csproj b/src/libs/AutoSDK.CLI/Resources/src_helpers_FixOpenApiSpec_FixOpenApiSpec.csproj index deaad9290c..9dd9ed85f2 100644 --- a/src/libs/AutoSDK.CLI/Resources/src_helpers_FixOpenApiSpec_FixOpenApiSpec.csproj +++ b/src/libs/AutoSDK.CLI/Resources/src_helpers_FixOpenApiSpec_FixOpenApiSpec.csproj @@ -10,6 +10,7 @@ + diff --git a/src/libs/AutoSDK.CLI/Resources/src_helpers_FixOpenApiSpec_Program.cs b/src/libs/AutoSDK.CLI/Resources/src_helpers_FixOpenApiSpec_Program.cs index 3cb06845b7..adf998224f 100644 --- a/src/libs/AutoSDK.CLI/Resources/src_helpers_FixOpenApiSpec_Program.cs +++ b/src/libs/AutoSDK.CLI/Resources/src_helpers_FixOpenApiSpec_Program.cs @@ -1,23 +1,23 @@ +using AutoSDK.Helpers; using Microsoft.OpenApi; -using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Readers; var path = args[0]; -var text = await File.ReadAllTextAsync(path); +var yamlOrJson = await File.ReadAllTextAsync(path); -text = text - .Replace("openapi: 3.1.0", "openapi: 3.0.1") - .Replace("\"openapi\":\"3.1.0\"", "\"openapi\":\"3.0.1\"") - ; +if (OpenApi31Support.IsOpenApi31(yamlOrJson)) +{ + yamlOrJson = OpenApi31Support.ConvertToOpenApi30(yamlOrJson); +} -var openApiDocument = new OpenApiStringReader().Read(text, out var diagnostics); +var openApiDocument = new OpenApiStringReader().Read(yamlOrJson, out var diagnostics); //openApiDocument.Components.Schemas["GenerateCompletionRequest"]!.Properties["stream"]!.Default = new OpenApiBoolean(true); -text = openApiDocument.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); -_ = new OpenApiStringReader().Read(text, out diagnostics); +yamlOrJson = openApiDocument.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); +_ = new OpenApiStringReader().Read(yamlOrJson, out diagnostics); if (diagnostics.Errors.Count > 0) { @@ -29,5 +29,4 @@ Environment.Exit(1); } -await File.WriteAllTextAsync(path, text); -return; \ No newline at end of file +await File.WriteAllTextAsync(path, yamlOrJson); \ No newline at end of file