Skip to content

Commit

Permalink
Merge branch 'main' into fix/enum-serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet authored Nov 20, 2024
2 parents 788ffe6 + 8e4b644 commit d06d6d8
Show file tree
Hide file tree
Showing 23 changed files with 291 additions and 334 deletions.
2 changes: 1 addition & 1 deletion it/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<kiota-java.version>1.7.0</kiota-java.version>
<kiota-java.version>1.8.0</kiota-java.version>
</properties>

<dependencies>
Expand Down
6 changes: 3 additions & 3 deletions it/python/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ yapf==0.43.0

zipp==3.21.0 ; python_version >= '3.7'

aiohttp==3.11.2 ; python_version >= '3.6'
aiohttp==3.11.6 ; python_version >= '3.6'

aiosignal==1.3.1 ; python_version >= '3.7'

Expand Down Expand Up @@ -112,13 +112,13 @@ microsoft-kiota-serialization-form==1.6.2

microsoft-kiota-serialization-multipart==1.6.2

msal==1.31.0
msal==1.31.1

msal-extensions==1.2.0

multidict==6.1.0 ; python_version >= '3.7'

portalocker==2.10.1 ; python_version >= '3.5' and platform_system == 'Windows'
portalocker==3.0.0 ; python_version >= '3.5' and platform_system == 'Windows'

pycparser==2.22

Expand Down
128 changes: 74 additions & 54 deletions it/typescript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions it/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"prettier": "./.prettierrc.json",
"devDependencies": {
"@es-exec/esbuild-plugin-start": "^0.0.5",
"@stylistic/eslint-plugin-ts": "^2.10.1",
"@types/node": "^22.9.0",
"@typescript-eslint/eslint-plugin": "^8.14.0",
"@typescript-eslint/parser": "^8.14.0",
"@stylistic/eslint-plugin-ts": "^2.11.0",
"@types/node": "^22.9.1",
"@typescript-eslint/eslint-plugin": "^8.15.0",
"@typescript-eslint/parser": "^8.15.0",
"esbuild": "^0.24.0",
"eslint": "^9.15.0",
"eslint-config-prettier": "^9.1.0",
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.22" />
<PackageReference Include="Microsoft.OpenApi.ApiManifest" Version="0.5.5-preview" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.22" />
<PackageReference Include="Microsoft.Plugins.Manifest" Version="1.0.0-rc1" />
<PackageReference Include="Microsoft.Plugins.Manifest" Version="1.0.0-rc2" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public async Task<bool> GeneratePluginAsync(CancellationToken cancellationToken)
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, Directory.GetCurrentDirectory());
var pluginsService = new PluginsGenerationService(openApiDocument, openApiTree, config, Directory.GetCurrentDirectory(), logger);
await pluginsService.GenerateManifestAsync(cancellationToken).ConfigureAwait(false);
StopLogAndReset(sw, $"step {++stepId} - generate plugin - took");
return stepId;
Expand Down
26 changes: 20 additions & 6 deletions src/Kiota.Builder/Plugins/PluginsGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Kiota.Builder.Configuration;
using Kiota.Builder.Extensions;
using Kiota.Builder.OpenApiExtensions;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.ApiManifest;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Services;
Expand All @@ -23,9 +24,10 @@ public partial class PluginsGenerationService
private readonly OpenApiUrlTreeNode TreeNode;
private readonly GenerationConfiguration Configuration;
private readonly string WorkingDirectory;
private readonly ILogger<KiotaBuilder> Logger;

public PluginsGenerationService(OpenApiDocument document, OpenApiUrlTreeNode openApiUrlTreeNode,
GenerationConfiguration configuration, string workingDirectory)
GenerationConfiguration configuration, string workingDirectory, ILogger<KiotaBuilder> logger)
{
ArgumentNullException.ThrowIfNull(document);
ArgumentNullException.ThrowIfNull(openApiUrlTreeNode);
Expand All @@ -35,6 +37,7 @@ public PluginsGenerationService(OpenApiDocument document, OpenApiUrlTreeNode ope
TreeNode = openApiUrlTreeNode;
Configuration = configuration;
WorkingDirectory = workingDirectory;
Logger = logger;
}

private static readonly OpenAPIRuntimeComparer _openAPIRuntimeComparer = new();
Expand Down Expand Up @@ -258,7 +261,7 @@ private OpenApiDocument GetDocumentWithTrimmedComponentsAndResponses(OpenApiDocu

private PluginManifestDocument GetManifestDocument(string openApiDocumentPath)
{
var (runtimes, functions, conversationStarters) = GetRuntimesFunctionsAndConversationStartersFromTree(OAIDocument, Configuration.PluginAuthInformation, TreeNode, openApiDocumentPath);
var (runtimes, functions, conversationStarters) = GetRuntimesFunctionsAndConversationStartersFromTree(OAIDocument, Configuration.PluginAuthInformation, TreeNode, openApiDocumentPath, Logger);
var descriptionForHuman = OAIDocument.Info?.Description is string d && !string.IsNullOrEmpty(d) ? d : $"Description for {OAIDocument.Info?.Title}";
var manifestInfo = ExtractInfoFromDocument(OAIDocument.Info);
var pluginManifestDocument = new PluginManifestDocument
Expand Down Expand Up @@ -338,7 +341,7 @@ private sealed record OpenApiManifestInfo(
string ContactEmail = DefaultContactEmail);

private static (OpenApiRuntime[], Function[], ConversationStarter[]) GetRuntimesFunctionsAndConversationStartersFromTree(OpenApiDocument document, PluginAuthConfiguration? authInformation, OpenApiUrlTreeNode currentNode,
string openApiDocumentPath)
string openApiDocumentPath, ILogger<KiotaBuilder> logger)
{
var runtimes = new List<OpenApiRuntime>();
var functions = new List<Function>();
Expand All @@ -348,10 +351,21 @@ private static (OpenApiRuntime[], Function[], ConversationStarter[]) GetRuntimes
{
foreach (var operation in pathItem.Operations.Values.Where(static x => !string.IsNullOrEmpty(x.OperationId)))
{
var auth = configAuth;
try
{
auth = configAuth ?? GetAuth(operation.Security ?? document.SecurityRequirements);
}
catch (UnsupportedSecuritySchemeException e)
{
auth = new AnonymousAuth();
logger.LogWarning("Authentication warning: {OperationId} - {Message}", operation.OperationId, e.Message);
}

runtimes.Add(new OpenApiRuntime
{
// Configuration overrides document information
Auth = configAuth ?? GetAuth(operation.Security ?? document.SecurityRequirements),
Auth = auth,
Spec = new OpenApiRuntimeSpec { Url = openApiDocumentPath },
RunForFunctions = [operation.OperationId]
});
Expand All @@ -376,7 +390,7 @@ private static (OpenApiRuntime[], Function[], ConversationStarter[]) GetRuntimes

foreach (var node in currentNode.Children)
{
var (childRuntimes, childFunctions, childConversationStarters) = GetRuntimesFunctionsAndConversationStartersFromTree(document, authInformation, node.Value, openApiDocumentPath);
var (childRuntimes, childFunctions, childConversationStarters) = GetRuntimesFunctionsAndConversationStartersFromTree(document, authInformation, node.Value, openApiDocumentPath, logger);
runtimes.AddRange(childRuntimes);
functions.AddRange(childFunctions);
conversationStarters.AddRange(childConversationStarters);
Expand All @@ -391,7 +405,7 @@ private static Auth GetAuth(IList<OpenApiSecurityRequirement> securityRequiremen
const string tooManySchemesError = "Multiple security requirements are not supported. Operations can only list one security requirement.";
if (securityRequirements.Count > 1 || securityRequirements.FirstOrDefault()?.Keys.Count > 1)
{
throw new InvalidOperationException(tooManySchemesError);
throw new UnsupportedSecuritySchemeException(tooManySchemesError);
}
var security = securityRequirements.FirstOrDefault();
var opSecurity = security?.Keys.FirstOrDefault();
Expand Down
Loading

0 comments on commit d06d6d8

Please sign in to comment.