-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Use official OpenAPI spec. #78
Changes from all commits
0d61196
ab56d25
2ca0036
ee21827
b2e2d6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,72 @@ | ||
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 jsonOrYaml = await File.ReadAllTextAsync(path); | ||
|
||
if (OpenApi31Support.IsOpenApi31(jsonOrYaml)) | ||
{ | ||
jsonOrYaml = OpenApi31Support.ConvertToOpenApi30(jsonOrYaml); | ||
} | ||
|
||
var openApiDocument = new OpenApiStringReader().Read(jsonOrYaml, out var diagnostics); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling after parsing the OpenAPI document After parsing the OpenAPI document with You can implement error handling as follows: if (diagnostics.Errors.Count > 0)
{
foreach (var error in diagnostics.Errors)
{
Console.WriteLine(error.Message);
}
Environment.Exit(1);
} Place this code after line 17, before modifying |
||
openApiDocument.Components.Schemas["TextBlock"].Properties["type"].Enum = new List<IOpenApiAny> | ||
openApiDocument.Components.Schemas.Add("Ping", new OpenApiSchema | ||
{ | ||
new OpenApiString("text"), | ||
}; | ||
openApiDocument.Components.Schemas["ImageBlock"].Properties["type"].Enum = new List<IOpenApiAny> | ||
{ | ||
new OpenApiString("image"), | ||
}; | ||
openApiDocument.Components.Schemas["ToolUseBlock"]!.Properties["type"].Enum = new List<IOpenApiAny> | ||
Type = "object", | ||
Properties = new Dictionary<string, OpenApiSchema> | ||
{ | ||
["type"] = new() | ||
{ | ||
Enum = new List<IOpenApiAny> | ||
{ | ||
new OpenApiString("ping"), | ||
}, | ||
Type = "string", | ||
Default = new OpenApiString("ping"), | ||
}, | ||
}, | ||
Required = new HashSet<string> | ||
{ | ||
"type", | ||
}, | ||
}); | ||
openApiDocument.Components.Schemas["MessageStreamEvent"].OneOf.Add(new OpenApiSchema | ||
{ | ||
new OpenApiString("tool_use"), | ||
}; | ||
openApiDocument.Components.Schemas["ToolResultBlock"]!.Properties["type"].Enum = new List<IOpenApiAny> | ||
Reference = new OpenApiReference | ||
{ | ||
Type = ReferenceType.Schema, | ||
Id = "Ping", | ||
}, | ||
}); | ||
|
||
openApiDocument.Components.SecuritySchemes.Clear(); | ||
openApiDocument.Components.SecuritySchemes.Add("ApiKeyAuth", new OpenApiSecurityScheme | ||
{ | ||
new OpenApiString("tool_result"), | ||
}; | ||
Type = SecuritySchemeType.ApiKey, | ||
In = ParameterLocation.Header, | ||
Name = "x-api-key", | ||
}); | ||
|
||
openApiDocument.Components.Schemas["TextBlock"].Required.Add("type"); | ||
openApiDocument.Components.Schemas["ImageBlock"].Required.Add("type"); | ||
openApiDocument.Components.Schemas["ToolUseBlock"].Required.Add("type"); | ||
openApiDocument.Components.Schemas["ToolResultBlock"].Required.Add("type"); | ||
openApiDocument.SecurityRequirements.Clear(); | ||
openApiDocument.SecurityRequirements.Add(new OpenApiSecurityRequirement | ||
{ | ||
{ | ||
new OpenApiSecurityScheme | ||
{ | ||
Reference = new OpenApiReference | ||
{ | ||
Type = ReferenceType.SecurityScheme, | ||
Id = "ApiKeyAuth", | ||
}, | ||
}, | ||
new List<string>() | ||
} | ||
}); | ||
|
||
jsonOrYaml = openApiDocument.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); | ||
_ = new OpenApiStringReader().Read(jsonOrYaml, out diagnostics); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Consider upgrading to the stable version 0.27.0 instead of using pre-release version 0.27.1-dev.3
The current implementation uses AutoSDK version 0.27.1-dev.3, which is a pre-release version. The latest stable version available on NuGet is 0.27.0. Using a pre-release version in a production environment could introduce instability or breaking changes. Unless there's a specific feature in 0.27.1-dev.3 that's required, it's recommended to use the stable version 0.27.0.
🔗 Analysis chain
Confirm the appropriateness of using a pre-release version of
AutoSDK
The package version
0.27.1-dev.3
ofAutoSDK
appears to be a development or pre-release version. Consider whether it's appropriate to depend on a pre-release package, as it might introduce instability or unexpected changes. If possible, evaluate using the latest stable release.You can run the following script to check for the latest stable version of
AutoSDK
:🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 400