Skip to content

Commit

Permalink
feat(cli): Use OpenApi31Support in init command.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Oct 3, 2024
1 parent 1096453 commit b6a88cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.17" />
<PackageReference Include="AutoSDK" Version="0.26.1-dev.11" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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)
{
Expand All @@ -29,5 +29,4 @@
Environment.Exit(1);
}

await File.WriteAllTextAsync(path, text);
return;
await File.WriteAllTextAsync(path, yamlOrJson);

0 comments on commit b6a88cc

Please sign in to comment.