Skip to content

Commit 70fec71

Browse files
authored
Merge pull request #9 from kiota-generator
2 parents bb7dedd + 9b72aaf commit 70fec71

19 files changed

Lines changed: 572 additions & 224 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
configuration: [CSharp, VisualBasic]
19-
project: [Analyzers, CodeFixers, Extensions, HighPerformance, SourceGenerators, DynamicCast, Swagger]
19+
project: [Analyzers, CodeFixers, Extensions, HighPerformance, SourceGenerators, DynamicCast, Kiota]
2020
exclude:
2121
- configuration: VisualBasic
2222
project: DynamicCast
2323
- configuration: VisualBasic
24-
project: Swagger
24+
project: Kiota
2525

2626
env:
2727
PROJECT: ${{ matrix.project }}

CompilerPlatform.slnx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<BuildType Project="CSharp" />
1010
<Build Solution="VisualBasic|*" Project="false" />
1111
</Project>
12-
<Project Path="src/features/Riverside.CompilerPlatform.Features.Swagger/Riverside.CompilerPlatform.Features.Swagger.csproj" Id="ba9bb2cd-6a93-4e05-9e46-4917360831a2">
12+
<Project Path="src/features/Riverside.CompilerPlatform.Features.Kiota/Riverside.CompilerPlatform.Features.Kiota.csproj">
1313
<BuildType Project="CSharp" />
1414
<Build Solution="VisualBasic|*" Project="false" />
1515
</Project>
@@ -26,7 +26,7 @@
2626
<BuildType Project="CSharp" />
2727
<Build Solution="VisualBasic|*" Project="false" />
2828
</Project>
29-
<Project Path="tests/Riverside.CompilerPlatform.Features.Tests/Riverside.CompilerPlatform.Features.Tests.csproj" Id="198c5333-faf0-4f00-b4ed-f714bb5309c9" />
29+
<Project Path="tests/Riverside.CompilerPlatform.Features.Tests/Riverside.CompilerPlatform.Features.Tests.csproj" />
3030
<Project Path="tests/Riverside.CompilerPlatform.VisualBasic.Tests/Riverside.CompilerPlatform.VisualBasic.Tests.vbproj">
3131
<BuildType Project="VisualBasic" />
3232
<Build Solution="CSharp|*" Project="false" />

Directory.Build.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<Project>
2+
23
<Import Project="$(MSBuildThisFileDirectory)\eng\PackageMetadata.props" Condition="!$(MSBuildProjectName.Contains('Tests'))" />
34
<Import Project="$(MSBuildThisFileDirectory)\eng\CurrentVersion.props" />
5+
46
<PropertyGroup>
57
<RootDirectory>$(MSBuildThisFileDirectory)</RootDirectory>
68
<SourceDirectory>$(RootDirectory)src</SourceDirectory>
@@ -30,4 +32,5 @@
3032
<ItemGroup>
3133
<Compile Condition="'$(Language)' == 'C#' and '$(IsLangMT)' == 'true'" Include="$(ExtensionsDirectory)\GlobalUsings.cs" />
3234
</ItemGroup>
35+
3336
</Project>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<Kiota_MinLangVersion>7.3</Kiota_MinLangVersion>
5+
<Kiota_AuthPackageVersion>1.21.2</Kiota_AuthPackageVersion>
6+
<Kiota_BundlePackageVersion>1.21.2</Kiota_BundlePackageVersion>
7+
</PropertyGroup>
8+
9+
<!--<Target Name="Kiota_EnsureDependencies" BeforeTargets="CollectPackageReferences">
10+
<ItemGroup>
11+
<PackageReference
12+
Include="Microsoft.Kiota.Authentication.Azure"
13+
Version="$(Kiota_AuthPackageVersion)"
14+
Condition="'@(PackageReference->WithMetadataValue('Identity', 'Microsoft.Kiota.Authentication.Azure'))' == ''" />
15+
<PackageReference
16+
Include="Microsoft.Kiota.Bundle"
17+
Version="$(Kiota_BundlePackageVersion)"
18+
Condition="'@(PackageReference->WithMetadataValue('Identity', 'Microsoft.Kiota.Bundle'))' == ''" />
19+
</ItemGroup>
20+
</Target>-->
21+
22+
<Target Name="Kiota_ValidateLanguageAndFramework" BeforeTargets="CoreCompile">
23+
<ItemGroup>
24+
<_Kiota_TargetFramework Include="$(TargetFramework)" Condition="'$(TargetFramework)' != ''" />
25+
<_Kiota_TargetFramework Include="$(TargetFrameworks)" Condition="'$(TargetFrameworks)' != ''" />
26+
<_Kiota_InvalidFramework Include="@(_Kiota_TargetFramework)"
27+
Condition="!$([System.Text.RegularExpressions.Regex]::IsMatch('%(Identity)', '^netstandard2\.(0|1)$|^net462$|^net([8-9]|[1-9][0-9])(?:\.[0-9]+)?(?:[-.].*)?$'))" />
28+
</ItemGroup>
29+
30+
<Error
31+
Condition="'$(LangVersion)' == ''"
32+
Code="KG1001"
33+
Text="Riverside Kiota requires C# LangVersion 7.3 or later. Set &lt;LangVersion&gt;7.3&lt;/LangVersion&gt; or newer." />
34+
35+
<Error
36+
Condition="
37+
'$(LangVersion)' != ''
38+
and !($([System.String]::Copy('$(LangVersion)').Equals('latest', System.StringComparison.OrdinalIgnoreCase)))
39+
and !($([System.String]::Copy('$(LangVersion)').Equals('latestmajor', System.StringComparison.OrdinalIgnoreCase)))
40+
and !($([System.String]::Copy('$(LangVersion)').Equals('preview', System.StringComparison.OrdinalIgnoreCase)))
41+
and $([System.Text.RegularExpressions.Regex]::IsMatch('$(LangVersion)', '^[0-9]+(\.[0-9]+)?$'))
42+
and !$([MSBuild]::VersionGreaterThanOrEquals('$(LangVersion)', '$(Kiota_MinLangVersion)'))"
43+
Code="KG1002"
44+
Text="The Advanced Compiler Services for .NET library requires C# 7.3 or later. The current language version is '$(LangVersion)'." />
45+
46+
<Error
47+
Condition="
48+
'$(LangVersion)' != ''
49+
and !($([System.String]::Copy('$(LangVersion)').Equals('latest', System.StringComparison.OrdinalIgnoreCase)))
50+
and !($([System.String]::Copy('$(LangVersion)').Equals('latestmajor', System.StringComparison.OrdinalIgnoreCase)))
51+
and !($([System.String]::Copy('$(LangVersion)').Equals('preview', System.StringComparison.OrdinalIgnoreCase)))
52+
and !$([System.Text.RegularExpressions.Regex]::IsMatch('$(LangVersion)', '^[0-9]+(\.[0-9]+)?$'))"
53+
Code="KG1003"
54+
Text="The Advanced Compiler Services for .NET library requires C# 7.3 or later. Unsupported LangVersion value '$(LangVersion)'." />
55+
56+
<Error
57+
Condition="'@(_Kiota_InvalidFramework)' != ''"
58+
Code="KG1004"
59+
Text="The Advanced Compiler Services for .NET library supports only netstandard2.0, netstandard2.1, net462, and net8.0 or later. Invalid target framework(s): @(_Kiota_InvalidFramework, ', ')." />
60+
61+
<Warning
62+
Condition="'$(Nullable)' == '' or $([System.String]::Copy('$(Nullable)').Equals('disable', System.StringComparison.OrdinalIgnoreCase))"
63+
Code="KG2001"
64+
Text="Nullable is disabled. Consider enabling nullable reference types (&lt;Nullable&gt;enable&lt;/Nullable&gt;) for generated Kiota clients." />
65+
</Target>
66+
67+
</Project>

src/features/Riverside.CompilerPlatform.Features.Swagger/KiotaEngine.Enums.cs renamed to src/features/Riverside.CompilerPlatform.Features.Kiota/KiotaEngine.Enums.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Riverside.CompilerPlatform.Features.Swagger;
1+
namespace Riverside.CompilerPlatform.Features.Kiota;
22

33
partial class KiotaEngine
44
{

src/features/Riverside.CompilerPlatform.Features.Swagger/KiotaEngine.Methods.cs renamed to src/features/Riverside.CompilerPlatform.Features.Kiota/KiotaEngine.Methods.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using System.Text;
1+
using Riverside.CompilerPlatform.Helpers;
2+
using System.Text;
23

3-
namespace Riverside.CompilerPlatform.Features.Swagger;
4+
namespace Riverside.CompilerPlatform.Features.Kiota;
45

56
partial class KiotaEngine
67
{
@@ -13,19 +14,19 @@ partial class KiotaEngine
1314
/// </returns>
1415
public override string ToString()
1516
{
16-
var command = new StringBuilder().Append("kiota generate");
17+
var command = new StringBuilder().Append("generate");
1718

1819
if (!string.IsNullOrWhiteSpace(Path))
1920
{
20-
command.Append($" --openapi {Path}");
21+
command.Append($" --openapi {SanitizationHelpers.EscapeArg(Path!)}");
2122
}
2223
if (!string.IsNullOrWhiteSpace(Manifest))
2324
{
24-
command.Append($" --manifest {Manifest}");
25+
command.Append($" --manifest {SanitizationHelpers.EscapeArg(Manifest!)}");
2526
}
2627
if (!string.IsNullOrWhiteSpace(Output))
2728
{
28-
command.Append($" --output {Output}");
29+
command.Append($" --output {SanitizationHelpers.EscapeArg(Output!)}");
2930
}
3031
command.Append($" --language {Language}");
3132
if (!string.IsNullOrWhiteSpace(ClassName))
@@ -56,68 +57,68 @@ public override string ToString()
5657
{
5758
command.Append($" --additional-data {AdditionalData}");
5859
}
59-
if (Serializer is not null)
60+
if (Serializer is not null && Serializer.Length > 0)
6061
{
6162
var serializers = new StringBuilder().Append(" --serializer ");
6263
foreach (var serializer in Serializer)
6364
{
6465
serializers.Append(serializer + "|");
6566
}
66-
serializers.Remove(serializers.Length, 1); // remove final '|' char
67+
serializers.Remove(serializers.Length - 1, 1); // remove final '|' char
6768
command.Append(serializers.ToString());
6869
}
69-
if (Deserializer is not null)
70+
if (Deserializer is not null && Deserializer.Length > 0)
7071
{
7172
var deserializers = new StringBuilder().Append(" --deserializer ");
7273
foreach (var deserializer in Deserializer)
7374
{
7475
deserializers.Append(deserializer + "|");
7576
}
76-
deserializers.Remove(deserializers.Length, 1); // remove final '|' char
77+
deserializers.Remove(deserializers.Length - 1, 1); // remove final '|' char
7778
command.Append(deserializers.ToString());
7879
}
7980
if (CleanOutput is not null)
8081
{
8182
command.Append($" --clean-output {CleanOutput}");
8283
}
83-
if (StructuredMimeTypes is not null)
84+
if (StructuredMimeTypes is not null && StructuredMimeTypes.Length > 0)
8485
{
8586
var structuredMimeTypes = new StringBuilder().Append(" --structured-mime-types ");
8687
foreach (var structuredMimeType in StructuredMimeTypes)
8788
{
8889
structuredMimeTypes.Append(structuredMimeType + "|");
8990
}
90-
structuredMimeTypes.Remove(structuredMimeTypes.Length, 1); // remove final '|' char
91+
structuredMimeTypes.Remove(structuredMimeTypes.Length - 1, 1); // remove final '|' char
9192
command.Append(structuredMimeTypes.ToString());
9293
}
93-
if (IncludePath is not null)
94+
if (IncludePath is not null && IncludePath.Length > 0)
9495
{
9596
var includePaths = new StringBuilder().Append(" --include-path ");
9697
foreach (var includePath in IncludePath)
9798
{
9899
includePaths.Append(includePath + "|");
99100
}
100-
includePaths.Remove(includePaths.Length, 1); // remove final '|' char
101+
includePaths.Remove(includePaths.Length - 1, 1); // remove final '|' char
101102
command.Append(includePaths.ToString());
102103
}
103-
if (ExcludePath is not null)
104+
if (ExcludePath is not null && ExcludePath.Length > 0)
104105
{
105106
var excludePaths = new StringBuilder().Append(" --exclude-path ");
106107
foreach (var excludePath in ExcludePath)
107108
{
108109
excludePaths.Append(excludePath + "|");
109110
}
110-
excludePaths.Remove(excludePaths.Length, 1); // remove final '|' char
111+
excludePaths.Remove(excludePaths.Length - 1, 1); // remove final '|' char
111112
command.Append(excludePaths.ToString());
112113
}
113-
if (DisableValidationRules is not null)
114+
if (DisableValidationRules is not null && DisableValidationRules.Length > 0)
114115
{
115116
var disableValidationRules = new StringBuilder().Append(" --disable-validation-rules ");
116117
foreach (var disableValidationRule in DisableValidationRules)
117118
{
118119
disableValidationRules.Append(disableValidationRule + "|");
119120
}
120-
disableValidationRules.Remove(disableValidationRules.Length, 1); // remove final '|' char
121+
disableValidationRules.Remove(disableValidationRules.Length - 1, 1); // remove final '|' char
121122
command.Append(disableValidationRules.ToString());
122123
}
123124
if (ClearCache is not null)

src/features/Riverside.CompilerPlatform.Features.Swagger/KiotaEngine.cs renamed to src/features/Riverside.CompilerPlatform.Features.Kiota/KiotaEngine.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System.Text;
1+
using System.Diagnostics.CodeAnalysis;
22

3-
namespace Riverside.CompilerPlatform.Features.Swagger;
3+
namespace Riverside.CompilerPlatform.Features.Kiota;
44

55
/// <summary>
66
/// Represents the configuration and options for generating code using the Kiota engine.
@@ -128,6 +128,7 @@ public partial class KiotaEngine
128128
/// <param name="l">The target programming language for code generation.</param>
129129
/// <param name="c">The name of the root class to be generated. Can be null to use a default class name.</param>
130130
/// <param name="tam">The access modifier to apply to generated types. Can be null to use the default accessibility.</param>
131+
/// <param name="n">The namespace for the generated client class. Can be null to use the default namespace.</param>
131132
/// <param name="ll">The log level to use for diagnostic output during generation. Can be null to use the default log level.</param>
132133
/// <param name="b">Indicates whether to use a backing store for generated models. If null, the default behavior is used.</param>
133134
/// <param name="ebc">Indicates whether to exclude backward compatible code from the output. If null, the default behavior is used.</param>
@@ -141,14 +142,16 @@ public partial class KiotaEngine
141142
/// <param name="dvr">An array of validation rules to disable during generation. Can be null to enable all rules.</param>
142143
/// <param name="cc">Indicates whether to clear the internal cache before generation. If null, the default behavior is used.</param>
143144
/// <param name="dsv">Indicates whether to disable SSL validation for network operations. If null, the default behavior is used.</param>
144-
public KiotaEngine(string? d, string? a, string? o, GenerationLanguage l, string? c, Accessibility? tam, ConsoleLogLevel? ll, bool? b, bool? ebc, bool? ad, string[]? s, string[]? ds, bool? co, string[]? m, string[]? i, string[]? e, ValidationRules[]? dvr, bool? cc, bool? dsv)
145+
[SetsRequiredMembers]
146+
public KiotaEngine(string? d, string? a, string? o, GenerationLanguage l, string? c, Accessibility? tam, string? n, ConsoleLogLevel? ll, bool? b, bool? ebc, bool? ad, string[]? s, string[]? ds, bool? co, string[]? m, string[]? i, string[]? e, ValidationRules[]? dvr, bool? cc, bool? dsv)
145147
{
146148
Path = d;
147149
Manifest = a;
148150
Output = o;
149151
Language = l;
150152
ClassName = c;
151153
TypeAccessModifier = tam;
154+
NamespaceName = n;
152155
LogLevel = ll;
153156
BackingStore = b;
154157
ExcludeBackwardCompatible = ebc;

0 commit comments

Comments
 (0)