Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@
<NewtonsoftJsonBsonVersion>1.0.2</NewtonsoftJsonBsonVersion>
<NewtonsoftJsonVersion>13.0.1</NewtonsoftJsonVersion>
<NSwagApiDescriptionClientVersion>13.0.4</NSwagApiDescriptionClientVersion>
<KiotaApiDescriptionClientVersion>0.5.0-preview2</KiotaApiDescriptionClientVersion>
<KiotaDotnetAbstractionsVersion>1.0.0-preview8</KiotaDotnetAbstractionsVersion>
<KiotaDotnetSerializationJsonVersion>1.0.0-preview6</KiotaDotnetSerializationJsonVersion>
<KiotaDotnetSerializationTextVersion>1.0.0-preview3</KiotaDotnetSerializationTextVersion>
<KiotaDotnetAuthenticationAzureVersion>1.0.0-preview3</KiotaDotnetAuthenticationAzureVersion>
<KiotaDotnetHttpVersion>1.0.0-preview8</KiotaDotnetHttpVersion>
<PhotinoNETVersion>1.1.6</PhotinoNETVersion>
<MicrosoftPlaywrightVersion>1.17.3</MicrosoftPlaywrightVersion>
<PollyExtensionsHttpVersion>3.0.0</PollyExtensionsHttpVersion>
Expand Down
4 changes: 3 additions & 1 deletion src/Tools/Microsoft.dotnet-openapi/src/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ namespace Microsoft.DotNet.OpenApi;
public enum CodeGenerator
{
NSwagCSharp,
NSwagTypeScript
NSwagTypeScript,
KiotaCSharp,
KiotaTypeScript,
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,35 @@
<_Parameter2>$(NewtonsoftJsonVersion)</_Parameter2>
<_Parameter3>NSwagCSharp;NSwagTypeScript</_Parameter3>
</AssemblyAttribute>
<AssemblyAttribute Include="Microsoft.DotNet.Openapi.Tools.Internal.OpenApiDependencyAttribute">
<_Parameter1>Microsoft.OpenApi.Kiota.ApiDescription.Client</_Parameter1>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Referencing only this package, will updated projects using KiotaCSharp or KiotaTypeScript be able to successfully use a generated client❔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at the moment, they'll need at least Microsoft.Kiota.Abstractions for dotnet projects and @microsoft/kiota-abstractions for typescript projects to compile.

They'll also need Microsoft.Kiota.Http.HttpClientLibrary/@microsoft/kiota-http-fetch or an alternative implementation to execute the requests
They'll also need Microsoft.Kiota.Serialization.Json / @microsoft/kiota-serialization-json or an alternative implementation to handle serialization/deserialization.
And finally, they might need Microsoft.Kiota.Authentication.Azure/@microsoft/kiota-authentication-azure or an alternative if their API requires authentication.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆗 then this PR is not complete as-is. When using the NSwag generator options, the generated client is immediately useful and this should be the same.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would be the recommended approach from your point of view? add those dependencies to the APIDescription package?
Or add those dependencies to the target through the same mechanism we're adding the API description package?
I prefer the later as it provides more control to users over which dependencies and versions dependencies they bring to their project should they want to change things.

Also, how are the JS/TS/npm packages added? are they being wrapped in a nuget package? or is there a possibility to add a reference to an npm package? if so how?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add those dependencies to the target through the same mechanism we're adding the API description package?

This would be my preference.

how are the JS/TS/npm packages added?

I'm not sure what JS/TS/npm dependencies an NSwag client requires or how those dependencies are handled. For all I know, the generated client works standalone. @bradygaster do you have more information❔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the dependencies for dotnet. waiting on @bradygaster 's input for the typescript ones

<_Parameter2>$(KiotaApiDescriptionClientVersion)</_Parameter2>
<_Parameter3>KiotaCSharp;KiotaTypeScript</_Parameter3>
</AssemblyAttribute>
<AssemblyAttribute Include="Microsoft.DotNet.Openapi.Tools.Internal.OpenApiDependencyAttribute">
<_Parameter1>Microsoft.Kiota.Abstractions</_Parameter1>
<_Parameter2>$(KiotaDotnetAbstractionsVersion)</_Parameter2>
<_Parameter3>KiotaCSharp</_Parameter3>
</AssemblyAttribute>
<AssemblyAttribute Include="Microsoft.DotNet.Openapi.Tools.Internal.OpenApiDependencyAttribute">
<_Parameter1>Microsoft.Kiota.Serialization.Json</_Parameter1>
<_Parameter2>$(KiotaDotnetSerializationJsonVersion)</_Parameter2>
<_Parameter3>KiotaCSharp</_Parameter3>
</AssemblyAttribute>
<AssemblyAttribute Include="Microsoft.DotNet.Openapi.Tools.Internal.OpenApiDependencyAttribute">
<_Parameter1>Microsoft.Kiota.Serialization.Text</_Parameter1>
<_Parameter2>$(KiotaDotnetSerializationTextVersion)</_Parameter2>
<_Parameter3>KiotaCSharp</_Parameter3>
</AssemblyAttribute>
<AssemblyAttribute Include="Microsoft.DotNet.Openapi.Tools.Internal.OpenApiDependencyAttribute">
<_Parameter1>Microsoft.Kiota.Authentication.Azure</_Parameter1>
<_Parameter2>$(KiotaDotnetAuthenticationAzureVersion)</_Parameter2>
<_Parameter3>KiotaCSharp</_Parameter3>
</AssemblyAttribute>
<AssemblyAttribute Include="Microsoft.DotNet.Openapi.Tools.Internal.OpenApiDependencyAttribute">
<_Parameter1>Microsoft.Kiota.Http.HttpClientLibrary</_Parameter1>
<_Parameter2>$(KiotaDotnetHttpVersion)</_Parameter2>
<_Parameter3>KiotaCSharp</_Parameter3>
</AssemblyAttribute>
</ItemGroup>
</Project>
45 changes: 45 additions & 0 deletions src/Tools/Microsoft.dotnet-openapi/test/OpenApiAddFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,51 @@ public async Task OpenApi_Add_NSwagTypeScript()
Assert.Contains($"<OpenApiReference Include=\"{nswagJsonFile}\" CodeGenerator=\"NSwagTypeScript\" />", content);
}

[Fact]
public async Task OpenApi_Add_KiotaCSharp()
{
var project = CreateBasicProject(withOpenApi: true);
var nswagJsonFile = project.NSwagJsonFile;

var app = GetApplication();
var run = app.Execute(new[] { "add", "file", nswagJsonFile, "--code-generator", "KiotaCSharp" });

AssertNoErrors(run);

// csproj contents
var csproj = new FileInfo(project.Project.Path);
using var csprojStream = csproj.OpenRead();
using var reader = new StreamReader(csprojStream);
var content = await reader.ReadToEndAsync();
Assert.Contains("<PackageReference Include=\"Microsoft.OpenApi.Kiota.ApiDescription.Client\" Version=\"", content);
Assert.Contains("<PackageReference Include=\"Microsoft.Kiota.Abstractions\" Version=\"", content);
Assert.Contains("<PackageReference Include=\"Microsoft.Kiota.Serialization.Json\" Version=\"", content);
Assert.Contains("<PackageReference Include=\"Microsoft.Kiota.Serialization.Text\" Version=\"", content);
Assert.Contains("<PackageReference Include=\"Microsoft.Kiota.Authentication.Azure\" Version=\"", content);
Assert.Contains("<PackageReference Include=\"Microsoft.Kiota.Http.HttpClientLibrary\" Version=\"", content);
Assert.Contains($"<OpenApiReference Include=\"{nswagJsonFile}\" CodeGenerator=\"KiotaCSharp\" />", content);
}

[Fact]
public async Task OpenApi_Add_KiotaTypeScript()
{
var project = CreateBasicProject(withOpenApi: true);
var nswagJsonFile = project.NSwagJsonFile;

var app = GetApplication();
var run = app.Execute(new[] { "add", "file", nswagJsonFile, "--code-generator", "KiotaTypeScript" });

AssertNoErrors(run);

// csproj contents
var csproj = new FileInfo(project.Project.Path);
using var csprojStream = csproj.OpenRead();
using var reader = new StreamReader(csprojStream);
var content = await reader.ReadToEndAsync();
Assert.Contains("<PackageReference Include=\"Microsoft.OpenApi.Kiota.ApiDescription.Client\" Version=\"", content);
Assert.Contains($"<OpenApiReference Include=\"{nswagJsonFile}\" CodeGenerator=\"KiotaTypeScript\" />", content);
}

[Fact]
public async Task OpenApi_Add_FromJson()
{
Expand Down
65 changes: 65 additions & 0 deletions src/Tools/Microsoft.dotnet-openapi/test/OpenApiAddURLTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,71 @@ public async Task OpenApi_Add_Url_NSwagTypeScript()
}
}

[Fact]
public async Task OpenApi_Add_Url_KiotaCSharp()
{
var project = CreateBasicProject(withOpenApi: false);

var app = GetApplication();
var run = app.Execute(new[] { "add", "url", FakeOpenApiUrl, "--code-generator", "KiotaCSharp" });

AssertNoErrors(run);

var expectedJsonName = "filename.json";

// csproj contents
using var csprojStream = new FileInfo(project.Project.Path).OpenRead();
using var reader = new StreamReader(csprojStream);
var content = await reader.ReadToEndAsync();
Assert.Contains("<PackageReference Include=\"Microsoft.OpenApi.Kiota.ApiDescription.Client\" Version=\"", content);
Assert.Contains("<PackageReference Include=\"Microsoft.Kiota.Abstractions\" Version=\"", content);
Assert.Contains("<PackageReference Include=\"Microsoft.Kiota.Serialization.Json\" Version=\"", content);
Assert.Contains("<PackageReference Include=\"Microsoft.Kiota.Serialization.Text\" Version=\"", content);
Assert.Contains("<PackageReference Include=\"Microsoft.Kiota.Authentication.Azure\" Version=\"", content);
Assert.Contains("<PackageReference Include=\"Microsoft.Kiota.Http.HttpClientLibrary\" Version=\"", content);
Assert.Contains(
$@"<OpenApiReference Include=""{expectedJsonName}"" SourceUrl=""{FakeOpenApiUrl}"" CodeGenerator=""KiotaCSharp"" />", content);

var resultFile = Path.Combine(_tempDir.Root, expectedJsonName);
Assert.True(File.Exists(resultFile));
var jsonStream = new FileInfo(resultFile).OpenRead();
var jsonReader = new StreamReader(jsonStream);
var jsonContent = await jsonReader.ReadToEndAsync();
Assert.Equal(Content, jsonContent);
}

[Fact]
public async Task OpenApi_Add_Url_KiotaTypeScript()
{
var project = CreateBasicProject(withOpenApi: false);

var app = GetApplication();
var run = app.Execute(new[] { "add", "url", FakeOpenApiUrl, "--code-generator", "KiotaTypeScript" });

AssertNoErrors(run);

var expectedJsonName = "filename.json";

// csproj contents
using (var csprojStream = new FileInfo(project.Project.Path).OpenRead())
using (var reader = new StreamReader(csprojStream))
{
var content = await reader.ReadToEndAsync();
Assert.Contains("<PackageReference Include=\"Microsoft.OpenApi.Kiota.ApiDescription.Client\" Version=\"", content);
Assert.Contains(
$@"<OpenApiReference Include=""{expectedJsonName}"" SourceUrl=""{FakeOpenApiUrl}"" CodeGenerator=""KiotaTypeScript"" />", content);
}

var resultFile = Path.Combine(_tempDir.Root, expectedJsonName);
Assert.True(File.Exists(resultFile));
using (var jsonStream = new FileInfo(resultFile).OpenRead())
using (var reader = new StreamReader(jsonStream))
{
var content = await reader.ReadToEndAsync();
Assert.Equal(Content, content);
}
}

[Fact]
public async Task OpenApi_Add_Url_OutputFile()
{
Expand Down