Skip to content

Commit

Permalink
Merge pull request microsoft#4614 from microsoft/bugfix/cli-nullable
Browse files Browse the repository at this point in the history
- adds missing CLI nullable annotations for the generated code
  • Loading branch information
baywet authored May 7, 2024
2 parents 808055f + 851efe0 commit f6a0f51
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Aligns naming of sliced OpenAPI description generated by `plugin add` should be named `<plugin-name>-openapi.json|yml` [#4595](https://github.com/microsoft/kiota/issues/4595)
- Fixed RPC server to respect the `KIOTA_CONFIG_PREVIEW` flag.
- Added missing nullable directives for CLI generation.
- Fixed handling of nested arrays to be handled as `UntypedNode` instances [#4549](https://github.com/microsoft/kiota/issues/4549)
- Fixed `InvalidOperationException` thrown when serializing IBacked models with no changes present in the additional data in dotnet [microsoftgraph/msgraph-sdk-dotnet#2471](https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2471).
- Fixed `RequestConfiguration` Classes dropped in RequestBuilder methods in python [#4535](https://github.com/microsoft/kiota/issues/4535)
Expand Down
2 changes: 2 additions & 0 deletions src/Kiota.Builder/Writers/CLI/CliCodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ private void WriteCommandHandlerBodyOutput(LanguageWriter writer, in CodeMethod

if (originalMethod.PagingInformation != null)
{
writer.WriteLine(CSharpConventionService.NullableEnableDirective, false);
writer.WriteLine($"IOutputFormatter? {formatterVar} = null;");
writer.WriteLine(CSharpConventionService.NullableRestoreDirective, false);
}
if (originalMethod.ReturnType is CodeType type &&
conventions.GetTypeString(type, originalMethod) is { } typeString && !typeString.Equals("Stream", StringComparison.Ordinal))
Expand Down
6 changes: 4 additions & 2 deletions src/Kiota.Builder/Writers/CSharp/CSharpConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ public class CSharpConventionService : CommonLanguageConventionService
public const char NullableMarker = '?';
public static string NullableMarkerAsString => "?";
public override string ParseNodeInterfaceName => "IParseNode";
public const string NullableEnableDirective = "#nullable enable";
public const string NullableRestoreDirective = "#nullable restore";

public static void WriteNullableOpening(LanguageWriter writer)
{
ArgumentNullException.ThrowIfNull(writer);
writer.WriteLine($"#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER", false);
writer.WriteLine($"#nullable enable", false);
writer.WriteLine(NullableEnableDirective, false);
}
public static void WriteNullableMiddle(LanguageWriter writer)
{
ArgumentNullException.ThrowIfNull(writer);
writer.WriteLine($"#nullable restore", false);
writer.WriteLine(NullableRestoreDirective, false);
writer.WriteLine("#else", false);
}
public static void WriteNullableClosing(LanguageWriter writer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,9 @@ public void WritesExecutableCommandForPagedGetRequestModel()
Assert.Contains("var pagingData = new PageLinkData(requestInfo, null, itemName: \"item\", nextLinkName: \"nextLink\");", result);
Assert.Contains("var reqAdapter = invocationContext.GetRequestAdapter()", result);
Assert.Contains("var pageResponse = await pagingService.GetPagedDataAsync((info, token) => reqAdapter.SendNoContentAsync(info, cancellationToken: token), pagingData, all, cancellationToken);", result);
Assert.Contains("#nullable enable", result);
Assert.Contains("IOutputFormatter? formatter = null;", result);
Assert.Contains("#nullable restore", result);
Assert.Contains("if (pageResponse?.StatusCode >= 200 && pageResponse?.StatusCode < 300) {", result);
Assert.Contains("formatter = outputFormatterFactory.GetFormatter(output);", result);
Assert.Contains("response = (response != Stream.Null) ? await outputFilter.FilterOutputAsync(response, query, cancellationToken) : response", result);
Expand Down

0 comments on commit f6a0f51

Please sign in to comment.