-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ellizio/dev
1.15.0
- Loading branch information
Showing
28 changed files
with
787 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
name: test | ||
name: ci | ||
|
||
on: | ||
push: | ||
branches: [ "actions" ] | ||
branches: | ||
- '**' | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: 8.0.x | ||
|
||
- name: Restore dependencies | ||
run: dotnet restore | ||
|
||
- name: Build | ||
run: dotnet build --no-restore | ||
run: dotnet build --configuration Release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: release | ||
|
||
on: | ||
push: | ||
tags: | ||
- '*.*.*' | ||
|
||
env: | ||
NUGET_DIRECTORY: ${{ github.workspace }}/nuget | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: 8.0.x | ||
|
||
- name: Restore dependencies | ||
run: dotnet restore | ||
|
||
- name: Pack | ||
run: dotnet pack --configuration Release --output ${{ env.NUGET_DIRECTORY }} | ||
|
||
- name: Publish | ||
run: | | ||
for file in $(find "${{ env.NUGET_DIRECTORY }}" -type f -name "*.nupkg"); do | ||
dotnet nuget push "$file" --api-key "${{ secrets.GH_NUGET }}" --source https://nuget.pkg.github.com/ellizio/index.json --skip-duplicate | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Changelog | ||
|
||
## [1.15.0] | ||
- Auto-generation based on Swagger | ||
- Using Kiota 1.15.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,109 @@ | ||
# Kiota.Autogen | ||
# <p align="center"> Kiota.Autogen </p> | ||
|
||
<p align="center"> A set of libraries for auto-generating API clients using Kiota </p> | ||
|
||
--- | ||
|
||
## Libraries list | ||
|
||
- [![Kiota.Autogen.Swagger](https://buildstats.info/nuget/Kiota.Autogen.Swagger)](https://www.nuget.org/packages/Kiota.Autogen.Swagger/) [Kiota.Autogen.Swagger](src/Kiota.Autogen.Swagger) for generating API client based on `Swashbuckle.AspNetCore` | ||
|
||
## Basic Usage | ||
|
||
1. Add a `Class Library` project to the solution that contains WebApi project | ||
2. Add WebApi project reference with `ExcludeAssets="All"` | ||
```xml | ||
<ItemGroup> | ||
<ProjectReference Include="..\ExampleService.Api\ExampleService.Api.csproj" ExcludeAssets="All" /> | ||
</ItemGroup> | ||
``` | ||
3. Install `Kiota.Autogen.Swagger` with `PrivateAssets="All"` | ||
```xml | ||
<ItemGroup> | ||
<PackageReference Include="Kiota.Autogen.Swagger" Version="1.15.0" PrivateAssets="All" /> | ||
</ItemGroup> | ||
``` | ||
4. Install following `Kiota` packages | ||
```xml | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.9.9" /> | ||
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.9.9" /> | ||
<PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.9.9" /> | ||
<PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.9.9" /> | ||
<PackageReference Include="Microsoft.Kiota.Serialization.Multipart" Version="1.9.9" /> | ||
<PackageReference Include="Microsoft.Kiota.Serialization.Text" Version="1.9.9" /> | ||
</ItemGroup> | ||
``` | ||
5. Create a `gensettings.json` file with the following structure | ||
```jsonc | ||
[ | ||
{ | ||
"name": "WeatherClient", // API client name to be generated | ||
"namespace": "Weather.Client", // API client namespace | ||
"version": "v1" // WebApi Swagger document version | ||
}, | ||
{ | ||
"name": "WeatherClientNew", | ||
"namespace": "Weather.Client.New", | ||
"version": "v2" | ||
} | ||
] | ||
``` | ||
6. Set up `Class library` project to build as a nuget package | ||
```xml | ||
<PropertyGroup> | ||
... other properties | ||
|
||
<IsPackable>true</IsPackable> | ||
<PackageId>ExampleService.Client</PackageId> | ||
</PropertyGroup> | ||
``` | ||
7. Pack `Class library` project | ||
8. Enjoy using API client | ||
```csharp | ||
using Microsoft.Kiota.Abstractions.Authentication; | ||
using Microsoft.Kiota.Http.HttpClientLibrary; | ||
using Weather.Client; | ||
|
||
using var httpClient = new HttpClient(); | ||
httpClient.BaseAddress = new Uri("http://your_service_url"); | ||
|
||
var provider = new AnonymousAuthenticationProvider(); | ||
using var adapter = new HttpClientRequestAdapter(provider, httpClient: httpClient); | ||
var client = new WeatherClient(adapter); | ||
|
||
var forecasts = await client.Weatherforecast.GetAsync(); | ||
``` | ||
|
||
See [full example](examples/basic_swagger) | ||
|
||
## Advanced Usage | ||
|
||
You can provide your own implementations of Microsoft.Kiota.Abstractions from the `Class library` project if you need\ | ||
Usage: | ||
```csharp | ||
using Microsoft.Kiota.Abstractions.Authentication; | ||
using Microsoft.Kiota.Http.HttpClientLibrary; | ||
using Weather.Client; | ||
|
||
using var httpClient = new HttpClient(); | ||
httpClient.BaseAddress = new Uri("http://your_service_url"); | ||
|
||
var provider = new AnonymousAuthenticationProvider(); | ||
using var adapter = new HttpClientRequestAdapter(provider, new WeatherParseNodeFactory(), new WeatherSerializationWriterFactory(), httpClient: httpClient); | ||
var client = new WeatherClient(adapter); | ||
|
||
var forecasts = await client.Weatherforecast.GetAsync(); | ||
``` | ||
|
||
See [full example](examples/advanced) | ||
|
||
## More Examples | ||
|
||
See more examples [here](examples) | ||
|
||
## Additional References | ||
|
||
- [Changelog](CHANGELOG.md) | ||
- [Kiota](https://github.com/microsoft/kiota) | ||
- [Swashbuckle.AspNetCore](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) |
14 changes: 14 additions & 0 deletions
14
examples/advanced/ExampleService.Api/ExampleService.Api.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2"/> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
var summaries = new[] | ||
{ | ||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
}; | ||
|
||
app.MapGet("/weatherforecast", () => | ||
{ | ||
var forecast = Enumerable.Range(1, 5).Select(index => | ||
new WeatherForecast | ||
( | ||
DateOnly.FromDateTime(DateTime.Now.AddDays(index)), | ||
Random.Shared.Next(-20, 55), | ||
summaries[Random.Shared.Next(summaries.Length)] | ||
)) | ||
.ToArray(); | ||
return forecast; | ||
}) | ||
.WithName("GetWeatherForecast") | ||
.WithOpenApi(); | ||
|
||
app.Run(); | ||
|
||
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary) | ||
{ | ||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
} |
41 changes: 41 additions & 0 deletions
41
examples/advanced/ExampleService.Api/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:60353", | ||
"sslPort": 44347 | ||
} | ||
}, | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "http://localhost:5167", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "https://localhost:7125;http://localhost:5167", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
examples/advanced/ExampleService.Api/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
27 changes: 27 additions & 0 deletions
27
examples/advanced/ExampleService.Client/ExampleService.Client.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>true</IsPackable> | ||
<PackageId>ExampleService.Client</PackageId> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ExampleService.Api\ExampleService.Api.csproj" ExcludeAssets="All" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Kiota.Autogen.Swagger" Version="1.15.0" PrivateAssets="All" /> | ||
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.9.9" /> | ||
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.9.9" /> | ||
<PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.9.9" /> | ||
<PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.9.9" /> | ||
<PackageReference Include="Microsoft.Kiota.Serialization.Multipart" Version="1.9.9" /> | ||
<PackageReference Include="Microsoft.Kiota.Serialization.Text" Version="1.9.9" /> | ||
</ItemGroup> | ||
|
||
</Project> |
13 changes: 13 additions & 0 deletions
13
examples/advanced/ExampleService.Client/WeatherParseNodeFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Microsoft.Kiota.Abstractions.Serialization; | ||
|
||
namespace Weather.Client; | ||
|
||
public class WeatherParseNodeFactory : IParseNodeFactory | ||
{ | ||
public IParseNode GetRootParseNode(string contentType, Stream content) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public string ValidContentType { get; } | ||
} |
13 changes: 13 additions & 0 deletions
13
examples/advanced/ExampleService.Client/WeatherSerializationWriterFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Microsoft.Kiota.Abstractions.Serialization; | ||
|
||
namespace Weather.Client; | ||
|
||
public class WeatherSerializationWriterFactory : ISerializationWriterFactory | ||
{ | ||
public ISerializationWriter GetSerializationWriter(string contentType) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public string ValidContentType { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
{ | ||
"name": "WeatherClient", | ||
"namespace": "Weather.Client", | ||
"version": "v1" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleService.Api", "ExampleService.Api\ExampleService.Api.csproj", "{F5231CDA-3DDE-461D-A48C-B631DB986876}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleService.Client", "ExampleService.Client\ExampleService.Client.csproj", "{838C542F-EAA3-41F3-B0E9-70950DE32DF3}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{F5231CDA-3DDE-461D-A48C-B631DB986876}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{F5231CDA-3DDE-461D-A48C-B631DB986876}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{F5231CDA-3DDE-461D-A48C-B631DB986876}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{F5231CDA-3DDE-461D-A48C-B631DB986876}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{838C542F-EAA3-41F3-B0E9-70950DE32DF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{838C542F-EAA3-41F3-B0E9-70950DE32DF3}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{838C542F-EAA3-41F3-B0E9-70950DE32DF3}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{838C542F-EAA3-41F3-B0E9-70950DE32DF3}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
Oops, something went wrong.