Skip to content

Commit

Permalink
Merge pull request #5227 from microsoft/chore/upgrade-deps
Browse files Browse the repository at this point in the history
chore: upgrade dependencies feat: removes openai plugin generation
  • Loading branch information
baywet authored Aug 23, 2024
2 parents 857987e + 3211d88 commit 2d3ff39
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 40 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Removed OpenAI plugins generation since the service does not support them anymore.
- Fixed an issue where models would be missing when they had no properties and a single allOf entry. [#5014](https://github.com/microsoft/kiota/issues/5014)
- Reverts modification of responses in output openApi file when generating plugins [#4945](https://github.com/microsoft/kiota/issues/4945)
- Expand properties types with null type for Typescript. [#4993](https://github.com/microsoft/kiota-typescript/issues/1188)
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Kiota.Builder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<PackageReference Include="Microsoft.OpenApi" Version="1.6.17" />
<PackageReference Include="Microsoft.OpenApi.ApiManifest" Version="0.5.5-preview" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.17" />
<PackageReference Include="Microsoft.Plugins.Manifest" Version="0.0.7-preview" />
<PackageReference Include="Microsoft.Plugins.Manifest" Version="0.0.19-preview" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="YamlDotNet" Version="16.0.0" />
<ProjectReference Include="..\Kiota.Generated\KiotaGenerated.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Plugins/AuthComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public bool Equals(Auth? x, Auth? y)
public int GetHashCode([DisallowNull] Auth obj)
{
if (obj == null) return 0;
return obj.Type is null ? 0 : StringComparer.OrdinalIgnoreCase.GetHashCode(obj.Type.Value.ToString()) * 3;
return obj.Type is null ? 0 : StringComparer.OrdinalIgnoreCase.GetHashCode(obj.Type) * 3;
}
}
32 changes: 3 additions & 29 deletions src/Kiota.Builder/Plugins/PluginsGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public PluginsGenerationService(OpenApiDocument document, OpenApiUrlTreeNode ope
private static readonly OpenAPIRuntimeComparer _openAPIRuntimeComparer = new();
private const string ManifestFileNameSuffix = ".json";
private const string DescriptionPathSuffix = "openapi.yml";
private const string OpenAIManifestFileName = "openai-plugins";
public async Task GenerateManifestAsync(CancellationToken cancellationToken = default)
{
// 1. cleanup any namings to be used later on.
Expand All @@ -63,10 +62,10 @@ public async Task GenerateManifestAsync(CancellationToken cancellationToken = de

foreach (var pluginType in Configuration.PluginTypes)
{
var manifestFileName = pluginType == PluginType.OpenAI ? OpenAIManifestFileName : $"{Configuration.ClientClassName.ToLowerInvariant()}-{pluginType.ToString().ToLowerInvariant()}";
var manifestFileName = $"{Configuration.ClientClassName.ToLowerInvariant()}-{pluginType.ToString().ToLowerInvariant()}";
var manifestOutputPath = Path.Combine(Configuration.OutputPath, $"{manifestFileName}{ManifestFileNameSuffix}");
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
await using var fileStream = File.Create(manifestOutputPath, 4096);
await using var fileStream = pluginType == PluginType.OpenAI ? Stream.Null : File.Create(manifestOutputPath, 4096);
await using var writer = new Utf8JsonWriter(fileStream, new JsonWriterOptions { Indented = true });
#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task

Expand All @@ -90,8 +89,7 @@ public async Task GenerateManifestAsync(CancellationToken cancellationToken = de
apiManifest.Write(writer);
break;
case PluginType.OpenAI:
var pluginDocumentV1 = GetV1ManifestDocument(descriptionRelativePath);
pluginDocumentV1.Write(writer);
// OpenAI plugins have been retired and are no longer supported. They only require the OpenAPI description now.
break;
default:
throw new NotImplementedException($"The {pluginType} plugin is not implemented.");
Expand Down Expand Up @@ -129,29 +127,6 @@ private OpenApiDocument GetDocumentWithTrimmedComponentsAndResponses(OpenApiDocu
return OpenApiFilterService.CreateFilteredDocument(doc, predicate);
}

private PluginManifestDocument GetV1ManifestDocument(string openApiDocumentPath)
{
var descriptionForHuman = OAIDocument.Info?.Description.CleanupXMLString() is string d && !string.IsNullOrEmpty(d) ? d : $"Description for {OAIDocument.Info?.Title.CleanupXMLString()}";
var manifestInfo = ExtractInfoFromDocument(OAIDocument.Info);
return new PluginManifestDocument
{
SchemaVersion = "v1",
NameForHuman = OAIDocument.Info?.Title.CleanupXMLString(),
NameForModel = OAIDocument.Info?.Title.CleanupXMLString(),
DescriptionForHuman = descriptionForHuman,
DescriptionForModel = manifestInfo.DescriptionForModel ?? descriptionForHuman,
Auth = new V1AnonymousAuth(),
Api = new Api()
{
Type = ApiType.openapi,
URL = openApiDocumentPath
},
ContactEmail = manifestInfo.ContactEmail,
LogoUrl = manifestInfo.LogoUrl,
LegalInfoUrl = manifestInfo.LegalUrl,
};
}

private PluginManifestDocument GetManifestDocument(string openApiDocumentPath)
{
var (runtimes, functions) = GetRuntimesAndFunctionsFromTree(TreeNode, openApiDocumentPath);
Expand All @@ -162,7 +137,6 @@ private PluginManifestDocument GetManifestDocument(string openApiDocumentPath)
Schema = "https://aka.ms/json-schemas/copilot-extensions/v2.1/plugin.schema.json",
SchemaVersion = "v2.1",
NameForHuman = OAIDocument.Info?.Title.CleanupXMLString(),
// TODO name for model ???
DescriptionForHuman = descriptionForHuman,
DescriptionForModel = manifestInfo.DescriptionForModel ?? descriptionForHuman,
ContactEmail = manifestInfo.ContactEmail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public async Task GeneratesManifest(string inputPluginName, string expectedPlugi

Assert.True(File.Exists(Path.Combine(outputDirectory, $"{expectedPluginName.ToLower()}-apiplugin.json")));
Assert.True(File.Exists(Path.Combine(outputDirectory, $"{expectedPluginName.ToLower()}-apimanifest.json")));
Assert.True(File.Exists(Path.Combine(outputDirectory, OpenAIPluginFileName)));
// v1 plugins are not generated anymore
Assert.False(File.Exists(Path.Combine(outputDirectory, OpenAIPluginFileName)));
Assert.True(File.Exists(Path.Combine(outputDirectory, $"{expectedPluginName.ToLower()}-openapi.yml")));
Assert.False(File.Exists(Path.Combine(outputDirectory, "manifest.json")));
Assert.False(File.Exists(Path.Combine(outputDirectory, "color.png")));
Expand All @@ -106,14 +107,6 @@ public async Task GeneratesManifest(string inputPluginName, string expectedPlugi
Assert.Equal(2, resultingManifest.Document.Functions.Count);// all functions are generated despite missing operationIds
Assert.Equal(expectedPluginName, resultingManifest.Document.Namespace);// namespace is cleaned up.
Assert.Empty(resultingManifest.Problems);// no problems are expected with names

// Validate the v1 plugin
var v1ManifestContent = await File.ReadAllTextAsync(Path.Combine(outputDirectory, OpenAIPluginFileName));
using var v1JsonDocument = JsonDocument.Parse(v1ManifestContent);
var v1Manifest = PluginManifestDocument.Load(v1JsonDocument.RootElement);
Assert.NotNull(resultingManifest.Document);
Assert.Equal($"{expectedPluginName.ToLower()}-openapi.yml", v1Manifest.Document.Api.URL);
Assert.Empty(v1Manifest.Problems);
}
private const string ManifestFileName = "client-apiplugin.json";
private const string OpenAIPluginFileName = "openai-plugins.json";
Expand Down

0 comments on commit 2d3ff39

Please sign in to comment.