Skip to content

Commit

Permalink
Merge branch 'main' into fix/go-generation
Browse files Browse the repository at this point in the history
  • Loading branch information
rkodev authored Jun 18, 2024
2 parents cf0b654 + 9d8f071 commit 281dcd4
Show file tree
Hide file tree
Showing 23 changed files with 162 additions and 113 deletions.
41 changes: 40 additions & 1 deletion .github/workflows/project-auto-add.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
- name: Set Language
- name: Set Language to Project
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
Expand All @@ -108,3 +108,42 @@ jobs:
}
}
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f language_field=$LANGUAGE_FIELD_ID -f language_value=${{ env.LANGUAGE_OPTION_ID }} --silent
- name: Get label for selected language in repository
if: ${{ env.SELECTED_LANGUAGE != 'Multiple Languages'}}
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
gh api graphql -f query='
query($repoOwner: String!, $repoName: String!) {
repository(owner: $repoOwner, name: $repoName) {
id,
labels(first: 100) {
nodes{
id,
name
}
}
}
}' -f repoOwner=${{github.repository_owner}} -f repoName=${{github.event.repository.name}} > issue_data.json
echo 'LANGUAGELABEL_ID='$(jq --arg lang "$SELECTED_LANGUAGE" '.data.repository.labels.nodes[] | select(.name==$lang) | .id' issue_data.json) >> $GITHUB_ENV
- name: Add label to issue
if: ${{ env.SELECTED_LANGUAGE != 'Multiple Languages'}}
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
ISSUE_ID: ${{ github.event_name == 'issues' && github.event.issue.node_id || github.event.pull_request.node_id }}
run: |
gh api graphql -f query='
mutation (
$issue: ID!
$label: ID!
) {
addLabelsToLabelable(input: {
labelableId: $issue
labelIds : [$label]
}) {
clientMutationId
}
}' -f issue=$ISSUE_ID -f label=$LANGUAGELABEL_ID --silent
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Fixes bug with model names in Go generated from camel case namespace. [https://github.com/microsoftgraph/msgraph-sdk-go/issues/721]
- Plugins OpenAPI extensions are only added when generating plugins to reduce the risk of parsing errors. [#4834](https://github.com/microsoft/kiota/issues/4834)
- TypeScript imports are now using ES6 imports with the .js extension.
- Remove LINQ usage in generated code.
- Ensures descriptions are not empty in sliced OpenApi file when generating a plugin.
- Plugins do not emit parameters anymore. [#4841](https://github.com/microsoft/kiota/issues/4841)

## [1.15.0] - 2024-06-06

Expand Down Expand Up @@ -58,7 +63,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixes a bug where warnings about discriminator not being inherited were generated [#4761](https://github.com/microsoft/kiota/issues/4761)
- Fix scalar member composed type serialization in PHP [#2827](https://github.com/microsoft/kiota/issues/2827)
- Trims unused components from output openApi document when generating plugins [#4672](https://github.com/microsoft/kiota/issues/4672)
- Fixes missing imports for UntypedNode when backingstore is enabled in Java.
- Fixes missing imports for UntypedNode when backingstore is enabled in Java.
- Renames `name_to_be_defined` plugin type to `apiplugin` [#4713](https://github.com/microsoft/kiota/issues/4713)

## [1.14.0] - 2024-05-02
Expand Down Expand Up @@ -622,7 +627,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed unused generated import for PHP Generation.
- Fixed a bug where long namespaces would make Ruby packaging fail.
- Fixed a bug where classes with namespace names are generated outside namespace in Python. [#2188](https://github.com/microsoft/kiota/issues/2188)
- Changed signature of escaped reserved names from {x}_escaped to {x}_ in line with Python style guides.
- Changed signature of escaped reserved names from {x}*escaped to {x}* in line with Python style guides.
- Add null checks in generated Shell language code.
- Fixed a bug where Go indexers would fail to pass the index parameter.
- Fixed a bug where path segments with parameters could be missing words. [#2209](https://github.com/microsoft/kiota/issues/2209)
Expand Down Expand Up @@ -1371,4 +1376,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Initial GitHub release

4 changes: 2 additions & 2 deletions it/csharp/dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.11.4" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.9.5" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.9.6" />
<PackageReference Include="Microsoft.Kiota.Authentication.Azure" Version="1.1.7" />
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.4.3" />
<PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.2.4" />
Expand All @@ -21,4 +21,4 @@
<Compile Remove="basic\**" />
</ItemGroup>

</Project>
</Project>
4 changes: 2 additions & 2 deletions it/python/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ tomlkit==0.12.5 ; python_version >= '3.7'

typing-extensions==4.12.2 ; python_version >= '3.7'

urllib3==2.2.1 ; python_version >= '3.7'
urllib3==2.2.2 ; python_version >= '3.7'

wrapt==1.15.0 ; python_version < '3.11'

Expand Down Expand Up @@ -112,7 +112,7 @@ microsoft-kiota-serialization-form==0.1.0

microsoft-kiota-serialization-multipart==0.1.0

msal==1.28.0
msal==1.28.1

msal-extensions==1.1.0

Expand Down
3 changes: 2 additions & 1 deletion scripts/update-versions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ function Get-LatestNugetVersion {

$url = "https://api.nuget.org/v3/registration5-gz-semver2/$($packageId.ToLowerInvariant())/index.json"
$response = Invoke-RestMethod -Uri $url -Method Get
$response.items[0].upper
$version = $response.items | Select-Object -ExpandProperty upper | ForEach-Object { [System.Management.Automation.SemanticVersion]$_ } | sort-object | Select-Object -Last 1
$version.ToString()
}
# Get the latest github release
function Get-LatestGithubRelease {
Expand Down
21 changes: 21 additions & 0 deletions src/Kiota.Builder/Extensions/OpenApiSettingsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using Kiota.Builder.OpenApiExtensions;
using Microsoft.OpenApi.Readers;

namespace Kiota.Builder.Extensions;
public static class OpenApiSettingsExtensions
{
/// <summary>
/// Adds the OpenAPI extensions used for plugins generation.
/// </summary>
public static void AddPluginsExtensions(this OpenApiReaderSettings settings)
{
ArgumentNullException.ThrowIfNull(settings);
settings.ExtensionParsers.TryAdd(OpenApiLogoExtension.Name, static (i, _) => OpenApiLogoExtension.Parse(i));
settings.ExtensionParsers.TryAdd(OpenApiDescriptionForModelExtension.Name, static (i, _) => OpenApiDescriptionForModelExtension.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));
}
}
6 changes: 6 additions & 0 deletions src/Kiota.Builder/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security;
using System.Security.Cryptography;
Expand Down Expand Up @@ -293,4 +294,9 @@ public static bool EqualsIgnoreCase(this string? a, string? b)

public static string TrimSuffix(this string s, string suffix, StringComparison stringComparison = StringComparison.Ordinal) =>
!string.IsNullOrEmpty(s) && !string.IsNullOrEmpty(suffix) && s.EndsWith(suffix, stringComparison) ? s[..^suffix.Length] : s;
public static string GetFileExtension(this string path)
{
if (string.IsNullOrEmpty(path)) return string.Empty;
return Path.GetExtension(path).TrimStart('.');
}
}
8 changes: 2 additions & 6 deletions src/Kiota.Builder/OpenApiDocumentDownloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,9 @@ ex is SecurityException ||
RuleSet = ruleSet,
};
settings.AddMicrosoftExtensionParsers();
if (config.IsPluginConfiguration)
settings.AddPluginsExtensions();
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
27 changes: 3 additions & 24 deletions src/Kiota.Builder/Plugins/PluginsGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ private OpenApiDocument GetDocumentWithTrimmedComponentsAndResponses(OpenApiDocu
//empty out all the responses with a single empty 2XX
foreach (var operation in doc.Paths.SelectMany(static item => item.Value.Operations.Values))
{
var responseDescription = operation.Responses.Values.Select(static response => response.Description)
.FirstOrDefault(static desc => !string.IsNullOrEmpty(desc)) ?? "Api Response";
operation.Responses = new OpenApiResponses()
{
{
"2XX",new OpenApiResponse
{
Description = responseDescription,
Content = new Dictionary<string, OpenApiMediaType>
{
{
Expand Down Expand Up @@ -246,35 +249,13 @@ private static (OpenApiRuntime[], Function[]) GetRuntimesAndFunctionsFromTree(Op
},
RunForFunctions = [operation.OperationId]
});
var oasParameters = operation.Parameters
.Union(pathItem.Parameters.Where(static x => x.In is ParameterLocation.Path))
.Where(static x => x.Schema?.Type is not null && scalarTypes.Contains(x.Schema.Type))
.ToArray();
//TODO add request body

functions.Add(new Function
{
Name = operation.OperationId,
Description =
operation.Summary.CleanupXMLString() is string summary && !string.IsNullOrEmpty(summary)
? summary
: operation.Description.CleanupXMLString(),
Parameters = oasParameters.Length == 0
? null
: new Parameters
{
Type = "object",
Properties = new Properties(oasParameters.ToDictionary(
static x => x.Name,
static x => new FunctionParameter()
{
Type = x.Schema.Type ?? string.Empty,
Description = x.Description.CleanupXMLString(),
Default = x.Schema.Default?.ToString() ?? string.Empty,
//TODO enums
})),
Required = oasParameters.Where(static x => x.Required).Select(static x => x.Name).ToList()
},
States = GetStatesFromOperation(operation),
});
}
Expand Down Expand Up @@ -321,6 +302,4 @@ rExtRaw is T rExt &&
}
return null;
}
private static readonly HashSet<string> scalarTypes = new(StringComparer.OrdinalIgnoreCase) { "string", "number", "integer", "boolean" };
//TODO validate this is right, in OAS integer are under type number for the json schema, but integer is ok for query parameters
}
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Refiners/CSharpRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected static void MakeEnumPropertiesNullable(CodeElement currentElement)
new (static x => x is CodeClass @class && @class.IsOfKind(CodeClassKind.RequestBuilder),
"System.Threading.Tasks", "Task"),
new (static x => x is CodeClass @class && @class.IsOfKind(CodeClassKind.Model, CodeClassKind.RequestBuilder),
"System.Linq", "Enumerable"),
ExtensionsNamespaceName, "Enumerable"),
new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.ClientConstructor) &&
method.Parameters.Any(y => y.IsOfKind(CodeParameterKind.BackingStore)),
StoreNamespaceName, "IBackingStoreFactory", "IBackingStoreFactorySingleton"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public async Task UpdateStateFromConfigurationAsync(GenerationConfiguration gene
manifest.ApiDependencies.AddOrReplace(generationConfiguration.ClientClassName, generationConfiguration.ToApiDependency(inputConfigurationHash, templatesWithOperations, WorkingDirectory));
await workspaceConfigurationStorageService.UpdateWorkspaceConfigurationAsync(wsConfig, manifest, cancellationToken).ConfigureAwait(false);
if (descriptionStream != Stream.Null)
await descriptionStorageService.UpdateDescriptionAsync(generationConfiguration.ClientClassName, descriptionStream, new Uri(generationConfiguration.OpenAPIFilePath).GetFileExtension(), cancellationToken).ConfigureAwait(false);
await descriptionStorageService.UpdateDescriptionAsync(generationConfiguration.ClientClassName, descriptionStream, generationConfiguration.OpenAPIFilePath.GetFileExtension(), cancellationToken).ConfigureAwait(false);
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class CodeMethodWriter : BaseElementWriter<CodeMethod, CSharpConventionSe
{
public CodeMethodWriter(CSharpConventionService conventionService) : base(conventionService)
{

}

public override void WriteCodeElement(CodeMethod codeElement, LanguageWriter writer)
{
ArgumentNullException.ThrowIfNull(codeElement);
Expand Down Expand Up @@ -350,7 +350,7 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me
{
if (isCollection)
{
var collectionMethod = propType.IsArray ? "?.ToArray()" : "?.ToList()";
var collectionMethod = propType.IsArray ? "?.AsArray()" : "?.AsList()";
if (currentType.TypeDefinition == null)
return $"GetCollectionOfPrimitiveValues<{propertyType}>(){collectionMethod}";
else if (currentType.TypeDefinition is CodeEnum)
Expand Down Expand Up @@ -407,7 +407,7 @@ protected void WriteRequestExecutorBody(CodeMethod codeElement, RequestParams re
};
writer.WriteLine($"{prefix}await RequestAdapter.{GetSendRequestMethodName(isVoid, codeElement, codeElement.ReturnType)}(requestInfo{returnTypeFactory}, {errorMappingVarName}, cancellationToken).ConfigureAwait(false);");
if (codeElement.ReturnType.IsCollection)
writer.WriteLine("return collectionResult?.ToList();");
writer.WriteLine("return collectionResult?.AsList();");
}
private const string RequestInfoVarName = "requestInfo";
private void WriteRequestGeneratorBody(CodeMethod codeElement, RequestParams requestParams, CodeClass currentClass, LanguageWriter writer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
using Kiota.Builder.Extensions;

namespace Kiota.Builder.Writers.TypeScript;
public class TypescriptRelativeImportManager : RelativeImportManager

public class TypescriptRelativeImportManager(string namespacePrefix, char namespaceSeparator) : RelativeImportManager(namespacePrefix, namespaceSeparator)
{
public TypescriptRelativeImportManager(string namespacePrefix, char namespaceSeparator) : base(namespacePrefix, namespaceSeparator)
{
}
/// <summary>
/// Returns the relative import path for the given using and import context namespace.
/// </summary>
Expand All @@ -26,9 +22,14 @@ public override (string, string, string) GetRelativeImportPathForUsing(CodeUsing
} : (codeUsing.Name, null);

if (typeDef == null)
return (importSymbol, codeUsing.Alias, "./"); // it's relative to the folder, with no declaration (default failsafe)
return (importSymbol, codeUsing.Alias, $"./{IndexFileName}"); // it's relative to the folder, with no declaration (default failsafe)
var importNamespace = typeDef.GetImmediateParentOfType<CodeNamespace>();
var importPath = GetImportRelativePathFromNamespaces(currentNamespace, importNamespace);
if (importPath.EndsWith('/'))
importPath += IndexFileName;
else
importPath += ".js";
return (importSymbol, codeUsing.Alias, importPath);
}
private const string IndexFileName = "index.js";
}
2 changes: 1 addition & 1 deletion src/kiota/KiotaPluginCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static Command GetRemoveCommand()
}
public static Command GetGenerateCommand()
{
var pluginNameOption = GetPluginNameOption();
var pluginNameOption = GetPluginNameOption(false);
var logLevelOption = KiotaHost.GetLogLevelOption();
var refreshOption = KiotaClientCommands.GetRefreshOption();
var command = new Command("generate", "Generates one or all plugin from the Kiota configuration")
Expand Down
Loading

0 comments on commit 281dcd4

Please sign in to comment.