Skip to content

Commit

Permalink
Merge branch 'main' into andrueastman/fixmutipleparams
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet authored Apr 19, 2024
2 parents 9f95d28 + 3987aae commit d625d92
Show file tree
Hide file tree
Showing 53 changed files with 1,820 additions and 145 deletions.
67 changes: 59 additions & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net8.0/kiota.dll",
"args": ["search", "microsoft"],
"args": [
"search",
"microsoft"
],
"cwd": "${workspaceFolder}/src/kiota",
"console": "internalConsole",
"stopAtEntry": false
Expand All @@ -207,7 +210,10 @@
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net8.0/kiota.dll",
"args": ["search", "test"],
"args": [
"search",
"test"
],
"cwd": "${workspaceFolder}/src/kiota",
"console": "internalConsole",
"stopAtEntry": false
Expand Down Expand Up @@ -249,7 +255,11 @@
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net8.0/kiota.dll",
"args": ["info", "-l", "CSharp"],
"args": [
"info",
"-l",
"CSharp"
],
"cwd": "${workspaceFolder}/src/kiota",
"console": "internalConsole",
"stopAtEntry": false
Expand All @@ -260,7 +270,11 @@
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net8.0/kiota.dll",
"args": ["update", "-o", "${workspaceFolder}/samples"],
"args": [
"update",
"-o",
"${workspaceFolder}/samples"
],
"cwd": "${workspaceFolder}/src/kiota",
"console": "internalConsole",
"stopAtEntry": false
Expand All @@ -271,7 +285,10 @@
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net8.0/kiota.dll",
"args": ["workspace", "migrate"],
"args": [
"workspace",
"migrate"
],
"cwd": "${workspaceFolder}/samples/msgraph-mail/dotnet",
"console": "internalConsole",
"stopAtEntry": false,
Expand All @@ -285,7 +302,10 @@
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net8.0/kiota.dll",
"args": ["client", "generate"],
"args": [
"client",
"generate"
],
"cwd": "${workspaceFolder}/samples/msgraph-mail/dotnet",
"console": "internalConsole",
"stopAtEntry": false,
Expand Down Expand Up @@ -314,13 +334,44 @@
"KIOTA_CONFIG_PREVIEW": "true"
}
},
{
"name": "Launch Plugin Add",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net8.0/kiota.dll",
"args": [
"plugin",
"add",
"--plugin-name",
"MicrosoftGraph",
"-d",
"https://raw.githubusercontent.com/microsoftgraph/msgraph-sdk-powershell/dev/openApiDocs/v1.0/Mail.yml",
"-i",
"**/messages",
"--type",
"ApiManifest",
"--type",
"microsoft"
],
"cwd": "${workspaceFolder}/samples/msgraph-mail/dotnet",
"console": "internalConsole",
"stopAtEntry": false,
"env": {
"KIOTA_CONFIG_PREVIEW": "true"
}
},
{
"name": "Launch Login (github - device)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net8.0/kiota.dll",
"args": ["login", "github", "device"],
"args": [
"login",
"github",
"device"
],
"cwd": "${workspaceFolder}/src/kiota",
"console": "internalConsole",
"stopAtEntry": false
Expand All @@ -332,4 +383,4 @@
"processId": "${command:pickProcess}"
}
]
}
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Fixed a bug where TypeScript deserialization would fail on Uppercase properties.[#4479](https://github.com/microsoft/kiota/issues/4479)
- Changed URI template generation to reuse templates when required templates are absent across operations.
- Updated reserved name providers for Java and Php so that "object" can be escaped.
- Do not generate CS8603 warnings when enabling backing store in CSharp generation.
- Fixes request builder disambiguation when child nodes had different prefixes for different paths with same parameters.[#4448](https://github.com/microsoft/kiota/issues/4448)
- Do not generate CS8603 warnings when enabling backing store in CSharp generation.

## [1.13.0] - 2024-04-04

Expand Down
2 changes: 1 addition & 1 deletion it/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions it/go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace Kiota.Builder.Configuration;
public enum ClientOperation
public enum ConsumerOperation
{
Add,
Edit,
Expand Down
7 changes: 4 additions & 3 deletions src/Kiota.Builder/Configuration/GenerationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Kiota.Builder.Configuration;
#pragma warning disable CA2227
#pragma warning disable CA1002
#pragma warning disable CA1056
public class GenerationConfiguration : ICloneable
{
Expand All @@ -30,7 +29,7 @@ public bool SkipGeneration
{
get; set;
}
public ClientOperation? Operation
public ConsumerOperation? Operation
{
get; set;
}
Expand All @@ -46,6 +45,7 @@ public string ModelsNamespaceName
get => $"{ClientNamespaceName}{NamespaceNameSeparator}{ModelsNamespaceSegmentName}";
}
public GenerationLanguage Language { get; set; } = GenerationLanguage.CSharp;
public HashSet<PluginType> PluginTypes { get; set; } = [];
public string? ApiRootUrl
{
get; set;
Expand Down Expand Up @@ -150,6 +150,7 @@ public object Clone()
SkipGeneration = SkipGeneration,
Operation = Operation,
PatternsOverride = new(PatternsOverride ?? Enumerable.Empty<string>(), StringComparer.OrdinalIgnoreCase),
PluginTypes = new(PluginTypes ?? Enumerable.Empty<PluginType>()),
};
}
private static readonly StringIEnumerableDeepComparer comparer = new();
Expand Down Expand Up @@ -185,7 +186,7 @@ public ApiDependency ToApiDependency(string configurationHash, Dictionary<string
};
return dependency;
}
public bool IsPluginConfiguration => PluginTypes.Count != 0;
}
#pragma warning restore CA1056
#pragma warning restore CA1002
#pragma warning restore CA2227
6 changes: 4 additions & 2 deletions src/Kiota.Builder/Kiota.Builder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@
<PackageReference Include="Microsoft.OpenApi" Version="1.6.14" />
<PackageReference Include="Microsoft.OpenApi.ApiManifest" Version="0.5.4-preview" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.14" />
<PackageReference Include="Microsoft.Plugins.Manifest" Version="0.0.6-preview" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="YamlDotNet" Version="15.1.2" />
<ProjectReference Include="..\Kiota.Generated\KiotaGenerated.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\Kiota.Generated\KiotaGenerated.csproj" OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="*.g.cs" />
</ItemGroup>
<ItemGroup>
<None Include="../../README.md" Pack="true" PackagePath="" />
</ItemGroup>
</Project>
</Project>
62 changes: 46 additions & 16 deletions src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Kiota.Builder.Logging;
using Kiota.Builder.Manifest;
using Kiota.Builder.OpenApiExtensions;
using Kiota.Builder.Plugins;
using Kiota.Builder.Refiners;
using Kiota.Builder.WorkspaceManagement;
using Kiota.Builder.Writers;
Expand Down Expand Up @@ -221,19 +222,61 @@ private void UpdateConfigurationFromOpenApiDocument()
return kiotaExt.LanguagesInformation;
return null;
}
/// <summary>
/// Generates the API plugins from the OpenAPI document
/// </summary>
/// <param name="cancellationToken">The cancellation token</param>
/// <returns>Whether the generated plugin was updated or not</returns>
public async Task<bool> GeneratePluginAsync(CancellationToken cancellationToken)
{
return await GenerateConsumerAsync(async (sw, stepId, openApiTree, CancellationToken) =>
{
if (config.PluginTypes.Contains(PluginType.OpenAI))
throw new NotImplementedException("The OpenAI plugin type is not supported for generation");
if (openApiDocument is null || openApiTree is null)
throw new InvalidOperationException("The OpenAPI document and the URL tree must be loaded before generating the plugins");
// generate plugin
sw.Start();
var pluginsService = new PluginsGenerationService(openApiDocument, openApiTree, config);
await pluginsService.GenerateManifestAsync(cancellationToken).ConfigureAwait(false);
StopLogAndReset(sw, $"step {++stepId} - generate plugin - took");
return stepId;
}, cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Generates the code from the OpenAPI document
/// </summary>
/// <param name="cancellationToken">The cancellation token</param>
/// <returns>Whether the generated code was updated or not</returns>
public async Task<bool> GenerateClientAsync(CancellationToken cancellationToken)
{
return await GenerateConsumerAsync(async (sw, stepId, openApiTree, CancellationToken) =>
{
// Create Source Model
sw.Start();
var generatedCode = CreateSourceModel(openApiTree);
StopLogAndReset(sw, $"step {++stepId} - create source model - took");

// RefineByLanguage
sw.Start();
await ApplyLanguageRefinement(config, generatedCode, cancellationToken).ConfigureAwait(false);
StopLogAndReset(sw, $"step {++stepId} - refine by language - took");

// Write language source
sw.Start();
await CreateLanguageSourceFilesAsync(config.Language, generatedCode, cancellationToken).ConfigureAwait(false);
StopLogAndReset(sw, $"step {++stepId} - writing files - took");
return stepId;
}, cancellationToken).ConfigureAwait(false);
}
private async Task<bool> GenerateConsumerAsync(Func<Stopwatch, int, OpenApiUrlTreeNode?, CancellationToken, Task<int>> innerGenerationSteps, CancellationToken cancellationToken)
{
var sw = new Stopwatch();
// Read input stream
var inputPath = config.OpenAPIFilePath;

if (config.Operation is ClientOperation.Add && await workspaceManagementService.IsClientPresent(config.ClientClassName, cancellationToken).ConfigureAwait(false))
if (config.Operation is ConsumerOperation.Add && await workspaceManagementService.IsConsumerPresent(config.ClientClassName, cancellationToken).ConfigureAwait(false))
throw new InvalidOperationException($"The client {config.ClientClassName} already exists in the workspace");

try
Expand All @@ -252,27 +295,14 @@ public async Task<bool> GenerateClientAsync(CancellationToken cancellationToken)

if (shouldGenerate)
{
// Create Source Model
sw.Start();
var generatedCode = CreateSourceModel(openApiTree);
StopLogAndReset(sw, $"step {++stepId} - create source model - took");

// RefineByLanguage
sw.Start();
await ApplyLanguageRefinement(config, generatedCode, cancellationToken).ConfigureAwait(false);
StopLogAndReset(sw, $"step {++stepId} - refine by language - took");

// Write language source
sw.Start();
await CreateLanguageSourceFilesAsync(config.Language, generatedCode, cancellationToken).ConfigureAwait(false);
StopLogAndReset(sw, $"step {++stepId} - writing files - took");
stepId = await innerGenerationSteps(sw, stepId, openApiTree, cancellationToken).ConfigureAwait(false);

await FinalizeWorkspaceAsync(sw, stepId, openApiTree, inputPath, cancellationToken).ConfigureAwait(false);
}
else
{
logger.LogInformation("No changes detected, skipping generation");
if (config.Operation is ClientOperation.Add or ClientOperation.Edit && config.SkipGeneration)
if (config.Operation is ConsumerOperation.Add or ConsumerOperation.Edit && config.SkipGeneration)
{
await FinalizeWorkspaceAsync(sw, stepId, openApiTree, inputPath, cancellationToken).ConfigureAwait(false);
}
Expand Down
8 changes: 7 additions & 1 deletion src/Kiota.Builder/OpenApiDocumentDownloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public OpenApiDocumentDownloadService(HttpClient httpClient, ILogger logger)
Stream input;
var isDescriptionFromWorkspaceCopy = false;
if (useKiotaConfig &&
config.Operation is ClientOperation.Edit or ClientOperation.Add &&
config.Operation is ConsumerOperation.Edit or ConsumerOperation.Add &&
workspaceManagementService is not null &&
await workspaceManagementService.GetDescriptionCopyAsync(config.ClientClassName, inputPath, config.CleanOutput, cancellationToken).ConfigureAwait(false) is { } descriptionStream)
{
Expand Down Expand Up @@ -114,6 +114,12 @@ ex is SecurityException ||
};
settings.AddMicrosoftExtensionParsers();
settings.ExtensionParsers.TryAdd(OpenApiKiotaExtension.Name, static (i, _) => OpenApiKiotaExtension.Parse(i));
settings.ExtensionParsers.TryAdd(OpenApiDescriptionForModelExtension.Name, static (i, _) => OpenApiDescriptionForModelExtension.Parse(i));
settings.ExtensionParsers.TryAdd(OpenApiLogoExtension.Name, static (i, _) => OpenApiLogoExtension.Parse(i));
settings.ExtensionParsers.TryAdd(OpenApiPrivacyPolicyUrlExtension.Name, static (i, _) => OpenApiPrivacyPolicyUrlExtension.Parse(i));
settings.ExtensionParsers.TryAdd(OpenApiLegalInfoUrlExtension.Name, static (i, _) => OpenApiLegalInfoUrlExtension.Parse(i));
settings.ExtensionParsers.TryAdd(OpenApiAiReasoningInstructionsExtension.Name, static (i, _) => OpenApiAiReasoningInstructionsExtension.Parse(i));
settings.ExtensionParsers.TryAdd(OpenApiAiRespondingInstructionsExtension.Name, static (i, _) => OpenApiAiRespondingInstructionsExtension.Parse(i));
try
{
var rawUri = config.OpenAPIFilePath.TrimEnd(KiotaBuilder.ForwardSlash);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.OpenApi;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Writers;

namespace Kiota.Builder.OpenApiExtensions;

public class OpenApiAiReasoningInstructionsExtension : IOpenApiExtension
{
public static string Name => "x-ai-reasoning-instructions";
#pragma warning disable CA1002 // Do not expose generic lists
public List<string> ReasoningInstructions { get; init; } = [];
#pragma warning restore CA1002 // Do not expose generic lists
public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
{
ArgumentNullException.ThrowIfNull(writer);
if (ReasoningInstructions != null &&
ReasoningInstructions.Count != 0)
{
writer.WriteStartArray();
foreach (var instruction in ReasoningInstructions)
{
writer.WriteValue(instruction);
}
writer.WriteEndArray();
}
}
public static OpenApiAiReasoningInstructionsExtension Parse(IOpenApiAny source)
{
if (source is not OpenApiArray rawArray) throw new ArgumentOutOfRangeException(nameof(source));
var result = new OpenApiAiReasoningInstructionsExtension();
result.ReasoningInstructions.AddRange(rawArray.OfType<OpenApiString>().Select(x => x.Value));
return result;
}
}
Loading

0 comments on commit d625d92

Please sign in to comment.