Skip to content

Commit

Permalink
Add workaround for kiota nullability bug at microsoft/kiota#3944 (com…
Browse files Browse the repository at this point in the history
  • Loading branch information
bkoelman committed Jan 17, 2025
1 parent 2212fc2 commit 1bc5703
Show file tree
Hide file tree
Showing 711 changed files with 6,830 additions and 19,161 deletions.
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<JsonApiDotNetCoreVersionPrefix>5.6.1</JsonApiDotNetCoreVersionPrefix>
<NuGetAuditMode>direct</NuGetAuditMode>
<NoWarn>$(NoWarn);NETSDK1215</NoWarn>
<KiotaPatchGeneratedCodeScriptPath>$(MSBuildThisFileDirectory)kiota-patch-generated-code.ps1</KiotaPatchGeneratedCodeScriptPath>
</PropertyGroup>

<PropertyGroup>
Expand Down
28 changes: 28 additions & 0 deletions kiota-patch-generated-code.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<#
Patches C# code generated by kiota.
Workaround for bug at https://github.com/microsoft/kiota/issues/3944#issuecomment-2597201229.
#>
param (
# Path to directory where kiota generated C# code.
[Parameter(Mandatory=$true)]
[string]$kiotaOutputDir
)

$osLineBreak = [System.Environment]::NewLine
$files = Get-ChildItem -Path $kiotaOutputDir -Recurse -Include *.cs

foreach ($file in $files)
{
$content = Get-Content $file -Raw

# add #nullable enable, suppress warning CS8625: Cannot convert null literal to non-nullable reference type.
$content = ($content -replace '// <auto-generated/>', "// <auto-generated/>$osLineBreak#nullable enable$osLineBreak#pragma warning disable CS8625")

# remove conditionals
$content = ($content -replace "(?s)#if NETSTANDARD2_1_OR_GREATER .*?$osLineBreak#nullable enable$osLineBreak(?<ifBody>.*?)$osLineBreak#nullable restore$osLineBreak#else$osLineBreak(?<elseBody>.*?)$osLineBreak#endif", "`$1")

# insert new line between member and next summary
$content = ($content -replace "}$osLineBreak(?<indentedSummary>\s+/// <summary>)", "}$osLineBreak$osLineBreak`$1")

Set-Content -Path $file -Value $content
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// <auto-generated/>
#nullable enable
#pragma warning disable CS8625
#pragma warning disable CS0618
using Microsoft.Kiota.Abstractions.Extensions;
using Microsoft.Kiota.Abstractions;
Expand All @@ -23,21 +25,25 @@ public partial class ApiRequestBuilder : BaseRequestBuilder
{
get => new global::OpenApiKiotaClientExample.GeneratedCode.Api.Operations.OperationsRequestBuilder(PathParameters, RequestAdapter);
}

/// <summary>The people property</summary>
public global::OpenApiKiotaClientExample.GeneratedCode.Api.People.PeopleRequestBuilder People
{
get => new global::OpenApiKiotaClientExample.GeneratedCode.Api.People.PeopleRequestBuilder(PathParameters, RequestAdapter);
}

/// <summary>The tags property</summary>
public global::OpenApiKiotaClientExample.GeneratedCode.Api.Tags.TagsRequestBuilder Tags
{
get => new global::OpenApiKiotaClientExample.GeneratedCode.Api.Tags.TagsRequestBuilder(PathParameters, RequestAdapter);
}

/// <summary>The todoItems property</summary>
public global::OpenApiKiotaClientExample.GeneratedCode.Api.TodoItems.TodoItemsRequestBuilder TodoItems
{
get => new global::OpenApiKiotaClientExample.GeneratedCode.Api.TodoItems.TodoItemsRequestBuilder(PathParameters, RequestAdapter);
}

/// <summary>
/// Instantiates a new <see cref="global::OpenApiKiotaClientExample.GeneratedCode.Api.ApiRequestBuilder"/> and sets the default values.
/// </summary>
Expand All @@ -46,6 +52,7 @@ public partial class ApiRequestBuilder : BaseRequestBuilder
public ApiRequestBuilder(Dictionary<string, object> pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api", pathParameters)
{
}

/// <summary>
/// Instantiates a new <see cref="global::OpenApiKiotaClientExample.GeneratedCode.Api.ApiRequestBuilder"/> and sets the default values.
/// </summary>
Expand All @@ -57,3 +64,4 @@ public ApiRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(r
}
}
#pragma warning restore CS0618

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// <auto-generated/>
#nullable enable
#pragma warning disable CS8625
#pragma warning disable CS0618
using Microsoft.Kiota.Abstractions.Extensions;
using Microsoft.Kiota.Abstractions.Serialization;
Expand All @@ -25,6 +27,7 @@ public partial class OperationsRequestBuilder : BaseRequestBuilder
public OperationsRequestBuilder(Dictionary<string, object> pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/operations", pathParameters)
{
}

/// <summary>
/// Instantiates a new <see cref="global::OpenApiKiotaClientExample.GeneratedCode.Api.Operations.OperationsRequestBuilder"/> and sets the default values.
/// </summary>
Expand All @@ -33,6 +36,7 @@ public OperationsRequestBuilder(Dictionary<string, object> pathParameters, IRequ
public OperationsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/operations", rawUrl)
{
}

/// <summary>
/// Performs multiple mutations in a linear and atomic manner.
/// </summary>
Expand All @@ -45,15 +49,8 @@ public OperationsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) :
/// <exception cref="global::OpenApiKiotaClientExample.GeneratedCode.Models.ErrorResponseDocument">When receiving a 404 status code</exception>
/// <exception cref="global::OpenApiKiotaClientExample.GeneratedCode.Models.ErrorResponseDocument">When receiving a 409 status code</exception>
/// <exception cref="global::OpenApiKiotaClientExample.GeneratedCode.Models.ErrorResponseDocument">When receiving a 422 status code</exception>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public async Task<global::OpenApiKiotaClientExample.GeneratedCode.Models.OperationsResponseDocument?> PostAsync(global::OpenApiKiotaClientExample.GeneratedCode.Models.OperationsRequestDocument body, Action<RequestConfiguration<DefaultQueryParameters>>? requestConfiguration = default, CancellationToken cancellationToken = default)
{
#nullable restore
#else
public async Task<global::OpenApiKiotaClientExample.GeneratedCode.Models.OperationsResponseDocument> PostAsync(global::OpenApiKiotaClientExample.GeneratedCode.Models.OperationsRequestDocument body, Action<RequestConfiguration<DefaultQueryParameters>> requestConfiguration = default, CancellationToken cancellationToken = default)
{
#endif
_ = body ?? throw new ArgumentNullException(nameof(body));
var requestInfo = ToPostRequestInformation(body, requestConfiguration);
var errorMapping = new Dictionary<string, ParsableFactory<IParsable>>
Expand All @@ -66,28 +63,23 @@ public OperationsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) :
};
return await RequestAdapter.SendAsync<global::OpenApiKiotaClientExample.GeneratedCode.Models.OperationsResponseDocument>(requestInfo, global::OpenApiKiotaClientExample.GeneratedCode.Models.OperationsResponseDocument.CreateFromDiscriminatorValue, errorMapping, cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Performs multiple mutations in a linear and atomic manner.
/// </summary>
/// <returns>A <see cref="RequestInformation"/></returns>
/// <param name="body">The request body</param>
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public RequestInformation ToPostRequestInformation(global::OpenApiKiotaClientExample.GeneratedCode.Models.OperationsRequestDocument body, Action<RequestConfiguration<DefaultQueryParameters>>? requestConfiguration = default)
{
#nullable restore
#else
public RequestInformation ToPostRequestInformation(global::OpenApiKiotaClientExample.GeneratedCode.Models.OperationsRequestDocument body, Action<RequestConfiguration<DefaultQueryParameters>> requestConfiguration = default)
{
#endif
_ = body ?? throw new ArgumentNullException(nameof(body));
var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters);
requestInfo.Configure(requestConfiguration);
requestInfo.Headers.TryAdd("Accept", "application/vnd.api+json;ext=atomic");
requestInfo.SetContentFromParsable(RequestAdapter, "application/vnd.api+json;ext=atomic", body);
return requestInfo;
}

/// <summary>
/// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored.
/// </summary>
Expand All @@ -100,3 +92,4 @@ public RequestInformation ToPostRequestInformation(global::OpenApiKiotaClientExa
}
}
#pragma warning restore CS0618

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// <auto-generated/>
#nullable enable
#pragma warning disable CS8625
#pragma warning disable CS0618
using Microsoft.Kiota.Abstractions.Extensions;
using Microsoft.Kiota.Abstractions.Serialization;
Expand All @@ -25,6 +27,7 @@ public partial class AssignedTodoItemsRequestBuilder : BaseRequestBuilder
public AssignedTodoItemsRequestBuilder(Dictionary<string, object> pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/people/{id}/assignedTodoItems{?query*}", pathParameters)
{
}

/// <summary>
/// Instantiates a new <see cref="global::OpenApiKiotaClientExample.GeneratedCode.Api.People.Item.AssignedTodoItems.AssignedTodoItemsRequestBuilder"/> and sets the default values.
/// </summary>
Expand All @@ -33,6 +36,7 @@ public AssignedTodoItemsRequestBuilder(Dictionary<string, object> pathParameters
public AssignedTodoItemsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/people/{id}/assignedTodoItems{?query*}", rawUrl)
{
}

/// <summary>
/// Retrieves the related todoItems of an individual person&apos;s assignedTodoItems relationship.
/// </summary>
Expand All @@ -41,15 +45,8 @@ public AssignedTodoItemsRequestBuilder(string rawUrl, IRequestAdapter requestAda
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
/// <exception cref="global::OpenApiKiotaClientExample.GeneratedCode.Models.ErrorResponseDocument">When receiving a 400 status code</exception>
/// <exception cref="global::OpenApiKiotaClientExample.GeneratedCode.Models.ErrorResponseDocument">When receiving a 404 status code</exception>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public async Task<global::OpenApiKiotaClientExample.GeneratedCode.Models.TodoItemCollectionResponseDocument?> GetAsync(Action<RequestConfiguration<global::OpenApiKiotaClientExample.GeneratedCode.Api.People.Item.AssignedTodoItems.AssignedTodoItemsRequestBuilder.AssignedTodoItemsRequestBuilderGetQueryParameters>>? requestConfiguration = default, CancellationToken cancellationToken = default)
{
#nullable restore
#else
public async Task<global::OpenApiKiotaClientExample.GeneratedCode.Models.TodoItemCollectionResponseDocument> GetAsync(Action<RequestConfiguration<global::OpenApiKiotaClientExample.GeneratedCode.Api.People.Item.AssignedTodoItems.AssignedTodoItemsRequestBuilder.AssignedTodoItemsRequestBuilderGetQueryParameters>> requestConfiguration = default, CancellationToken cancellationToken = default)
{
#endif
var requestInfo = ToGetRequestInformation(requestConfiguration);
var errorMapping = new Dictionary<string, ParsableFactory<IParsable>>
{
Expand All @@ -58,60 +55,43 @@ public AssignedTodoItemsRequestBuilder(string rawUrl, IRequestAdapter requestAda
};
return await RequestAdapter.SendAsync<global::OpenApiKiotaClientExample.GeneratedCode.Models.TodoItemCollectionResponseDocument>(requestInfo, global::OpenApiKiotaClientExample.GeneratedCode.Models.TodoItemCollectionResponseDocument.CreateFromDiscriminatorValue, errorMapping, cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Compare the returned ETag HTTP header with an earlier one to determine if the response has changed since it was fetched.
/// </summary>
/// <param name="cancellationToken">Cancellation token to use when cancelling requests</param>
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public async Task HeadAsync(Action<RequestConfiguration<global::OpenApiKiotaClientExample.GeneratedCode.Api.People.Item.AssignedTodoItems.AssignedTodoItemsRequestBuilder.AssignedTodoItemsRequestBuilderHeadQueryParameters>>? requestConfiguration = default, CancellationToken cancellationToken = default)
{
#nullable restore
#else
public async Task HeadAsync(Action<RequestConfiguration<global::OpenApiKiotaClientExample.GeneratedCode.Api.People.Item.AssignedTodoItems.AssignedTodoItemsRequestBuilder.AssignedTodoItemsRequestBuilderHeadQueryParameters>> requestConfiguration = default, CancellationToken cancellationToken = default)
{
#endif
var requestInfo = ToHeadRequestInformation(requestConfiguration);
await RequestAdapter.SendNoContentAsync(requestInfo, default, cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Retrieves the related todoItems of an individual person&apos;s assignedTodoItems relationship.
/// </summary>
/// <returns>A <see cref="RequestInformation"/></returns>
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public RequestInformation ToGetRequestInformation(Action<RequestConfiguration<global::OpenApiKiotaClientExample.GeneratedCode.Api.People.Item.AssignedTodoItems.AssignedTodoItemsRequestBuilder.AssignedTodoItemsRequestBuilderGetQueryParameters>>? requestConfiguration = default)
{
#nullable restore
#else
public RequestInformation ToGetRequestInformation(Action<RequestConfiguration<global::OpenApiKiotaClientExample.GeneratedCode.Api.People.Item.AssignedTodoItems.AssignedTodoItemsRequestBuilder.AssignedTodoItemsRequestBuilderGetQueryParameters>> requestConfiguration = default)
{
#endif
var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters);
requestInfo.Configure(requestConfiguration);
requestInfo.Headers.TryAdd("Accept", "application/vnd.api+json");
return requestInfo;
}

/// <summary>
/// Compare the returned ETag HTTP header with an earlier one to determine if the response has changed since it was fetched.
/// </summary>
/// <returns>A <see cref="RequestInformation"/></returns>
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public RequestInformation ToHeadRequestInformation(Action<RequestConfiguration<global::OpenApiKiotaClientExample.GeneratedCode.Api.People.Item.AssignedTodoItems.AssignedTodoItemsRequestBuilder.AssignedTodoItemsRequestBuilderHeadQueryParameters>>? requestConfiguration = default)
{
#nullable restore
#else
public RequestInformation ToHeadRequestInformation(Action<RequestConfiguration<global::OpenApiKiotaClientExample.GeneratedCode.Api.People.Item.AssignedTodoItems.AssignedTodoItemsRequestBuilder.AssignedTodoItemsRequestBuilderHeadQueryParameters>> requestConfiguration = default)
{
#endif
var requestInfo = new RequestInformation(Method.HEAD, UrlTemplate, PathParameters);
requestInfo.Configure(requestConfiguration);
return requestInfo;
}

/// <summary>
/// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored.
/// </summary>
Expand All @@ -121,40 +101,29 @@ public RequestInformation ToHeadRequestInformation(Action<RequestConfiguration<g
{
return new global::OpenApiKiotaClientExample.GeneratedCode.Api.People.Item.AssignedTodoItems.AssignedTodoItemsRequestBuilder(rawUrl, RequestAdapter);
}

/// <summary>
/// Retrieves the related todoItems of an individual person&apos;s assignedTodoItems relationship.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")]
public partial class AssignedTodoItemsRequestBuilderGetQueryParameters
{
/// <summary>For syntax, see the documentation for the [`include`](https://www.jsonapi.net/usage/reading/including-relationships.html)/[`filter`](https://www.jsonapi.net/usage/reading/filtering.html)/[`sort`](https://www.jsonapi.net/usage/reading/sorting.html)/[`page`](https://www.jsonapi.net/usage/reading/pagination.html)/[`fields`](https://www.jsonapi.net/usage/reading/sparse-fieldset-selection.html) query string parameters.</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
[QueryParameter("query")]
public string? Query { get; set; }
#nullable restore
#else
[QueryParameter("query")]
public string Query { get; set; }
#endif
}

/// <summary>
/// Compare the returned ETag HTTP header with an earlier one to determine if the response has changed since it was fetched.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")]
public partial class AssignedTodoItemsRequestBuilderHeadQueryParameters
{
/// <summary>For syntax, see the documentation for the [`include`](https://www.jsonapi.net/usage/reading/including-relationships.html)/[`filter`](https://www.jsonapi.net/usage/reading/filtering.html)/[`sort`](https://www.jsonapi.net/usage/reading/sorting.html)/[`page`](https://www.jsonapi.net/usage/reading/pagination.html)/[`fields`](https://www.jsonapi.net/usage/reading/sparse-fieldset-selection.html) query string parameters.</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
[QueryParameter("query")]
public string? Query { get; set; }
#nullable restore
#else
[QueryParameter("query")]
public string Query { get; set; }
#endif
}
}
}
#pragma warning restore CS0618

Loading

0 comments on commit 1bc5703

Please sign in to comment.